Skip to content Skip to sidebar Skip to footer

How To Use Python's Request Library To Make An Api Call With An Attachment And A Parameter

I am using the Request library to test ReST APIs. I am facing a problem while trying to trasform the below cURL to request library Call. curl https://upload.box.com/api/2.0/files/c

Solution 1:

I assume you mean the requests library?

If so, here is how I do it.

access_token = <user access token>
filename = <name of the file as you want it to appear on Box>
src_file = the actual file path
parent_id = the id of the folder you want to upload to

headers = { 'Authorization' : 'Bearer {0}'.format(access_token) }
url = 'https://upload.box.com/api/2.0/files/content'files = { 'filename': (filename, open(src_file,'rb')) }
data = { "parent_id": parent_id }
response = requests.post(url, data=data, files=files, headers=headers)
file_info = response.json()

Solution 2:

I followed the example given in http://www.snip2code.com/Snippet/67408/Show-progress-bar-when-uploading-a-file.

I was able to make a successful API call.

Post a Comment for "How To Use Python's Request Library To Make An Api Call With An Attachment And A Parameter"