Send data and files to Forge API using Python requests

Send data and files to Forge API using Python requests

Anonymous
Not applicable
911 Views
1 Reply
Message 1 of 2

Send data and files to Forge API using Python requests

Anonymous
Not applicable

I am trying to send data that identifies the photoscene ID and a dictionary of locally stored files to the Autodesk Recap API. If I send only the data, the response includes the correct photoscene ID. If I include files (using the read binary option), the request does not post any data and the API cannot identify the photoscene. I have successfully created a photoscene with Python requests and uploaded the images with curl, but would prefer to do all of this in a single Python function.

 

headers = {
    'Authorization': 'Bearer {}'.format(access_token),
    'Content-Type': 'multipart/form-data'
}
data = {
    'photosceneid': photoscene_id,
    'type': 'image'
}
files = {}
img_dir = os.listdir('Recap/')
for img in img_dir:
    files['file[{}]'.format(img_dir.index(img))] = open('Recap/' + img, 'rb')
post = requests.post(url='https://developer.api.autodesk.com/photo-to-3d/v1/file', headers=headers, data=data,
                     files=files)
0 Likes
Accepted solutions (1)
912 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Accepted solution

I removed "Content-Type" from headers as this is set by Requests and it worked.

0 Likes