I'm trying to upload a file in an API that just says:
REQUEST The request body should contain the contents of the file. https://developer.fortnox.se/documentation/resources/inbox/
What I've tried so far:
headers = {
"Access-Token": settings.FORTNOX_ACCESS_TOKEN,
"Client-Secret": settings.FORTNOX_CLIENT_SECRET,
"Content-Type": "multipart/form-data",
"Accept": "application/json",
}
file = open(invoice.file.path, 'rb').read()
r = requests.post("https://api.fortnox.se/3/inbox", data=file, headers=headers)
This gives me an error:
Ingen fil var uppladdad. (No file was uploaded)
headers = {
"Access-Token": settings.FORTNOX_ACCESS_TOKEN,
"Client-Secret": settings.FORTNOX_CLIENT_SECRET,
"Content-Type": "multipart/form-data",
"Accept": "application/json",
}
h = httplib2.Http()
file = open(invoice.file.path, 'rb').read()
resp, content = h.request('https://api.fortnox.se/3/inbox', "POST", body=file, headers=headers)
This gives me the same error:
Ingen fil var uppladdad. (No file was uploaded)
Are there any other ways to add the file to the request body, or am I doing something wrong here?
Thanks for any help.