Welcome to the new Box Support website. Check out all the details here on what’s changed.

Accessing files with Python

New post

Comments

2 comments

  • Rui Barbosa

    Hi Katie,

    I was not able to replicate your case, it may be related to streaming a big file, how big is your file?

    So considering a simple csv file like:

    itemType,itemID,name,description
    folder,176840203842,Cenotes,
    folder,176840211427,Eagle Ray Bay,
    folder,176841144813,Ras Mohamed,
    folder,176839738500,Sharks Bay,
    folder,176838773123,Thistlegorm,
    folder,175969946454,Tropicana,

    This sample code:

    def get_file_content(client:Client,file_id):
        file_content = client.file(file_id).content(file_version=None, byte_range=None)
        # file = client.file(file_id).get()
        # file_content = file.content(file_version=None, byte_range=None)
        s = str(file_content)
        data = StringIO(s)
        df = pd.read_csv(data)
        print(f"Data frame: {df}")
        return df

    Produces this output, returning the data frame (note: I'm unfamiliar with pandas):

    Data frame: Empty DataFrame
    Columns: [b'itemType, itemID, name, description\r\n
    folder, 176840203842, Cenotes, \r\n
    folder, 176840211427, Eagle Ray Bay, \r\n
    folder.1, 176841144813, Ras Mohamed, \r\n
    folder.2, 176839738500, Sharks Bay, \r\n
    folder.3, 176838773123, Thistlegorm, \r\n
    folder.4, 175969946454, Tropicana, \r\n']
    Index: []

    You can take a look at the full example here.

    Let me know if this helps or how we can explore this further.

     

    0
    Comment actions Permalink
  • Katie Brennan

    I think it might be a permissions issue. I am currently an 'editor' on the folder I'm trying to access. Are there further permissions needed? 

    0
    Comment actions Permalink

Post is closed for comments.