how to upload files using python with api ?

29 views
Skip to first unread message

youssef mahmoud

unread,
Oct 9, 2021, 6:53:06 PM10/9/21
to Assembla API Development
hi 
every time i try to upload files with python i got 
400 error or 404 tool not found , i don't know where what is issue with my code 

headers_a = {"X-Api-Key": assemblla_apikey, "X-Api-Secret": assemblla_apisecret,'Content-Type': 'multipart/form-data'}


attachment_file =  BytesIO(requests.get('http://127.0.0.1:8000'+attachment.attachment.url).content)
attachemnt_mimetype = magic.from_buffer(attachment_file.read(2048),mime=True)
 files = {'document[file]': (attachment_file.getvalue()),'document[attachable_type]':'Ticket','document[name]':attachment.attachment_name, 'document[attachable_id]':ticket_id}
attachment_reponse = requests.post(attachment_url, files=files, headers=headers_a)
Reply all
Reply to author
Forward
0 new messages