Search code examples
pythonibm-cloudobject-storagedata-science-experience

How do I access files on Bluemix Object Storage from Python on Data Science Experience?


I'd like to copy a file to local memory on DSX so that I can create a pandas dataframe using read_csv. I don't want to use the given "insert to code" option because that assumes column headers and it isn't as pretty to code. Here is my code:

import swiftclient

IBM_Objectstorage_Connection = swiftclient.Connection(key=objStorCred['password'],
                                                  authurl=objStorCred['auth_url'],
                                                  auth_version='3',
                                os_options={"project_id": objStorCred['projectId'],
                                            "user_id": objStorCred['userId'],
                                            "region_name": objStorCred['region']})

x = IBM_Objectstorage_Connection.get_account()

I've tried the object storage admin credentials and the credentials for the container. Neither work. I'm trying to copy what was done in this tutorial, but it doesn't seem to be working. Here is my error:

Authorization Failure. Authorization failed: The resource could not be found. (HTTP 404)

Any help would be greatly appreciated!


Solution

  • Did you take a look at the get_file_content(credentials) method mentioned in the following notebook:

    https://apsportal.ibm.com/analytics/notebooks/461e1a46-243c-4264-98fb-653884ed27f5/view?access_token=e5eb80cb75eae7e2d8ac4306eece1d1345a6c59a180eb284fb79aa04d3ccb7fe

    content_string = get_file_content(credentials_1)
    precipitation_df = pd.read_csv(content_string)
    

    I have used it many times before. Hope this helps.