My API:
class FileView(APIView):
parser_classes = (MultiPartParser,)
def post(self, request):
do something with request.FILES.dict().iteritems()
My requests file:
try:
headers = {
'content-type': "multipart/form-data",
'authorization': "Basic ZXNlbnRpcmVcYdddddddddddddd",
'cache-control': "no-cache",
}
myfile = {"file": ("filexxx", open(filepath, "rb"))}
response = requests.request("POST", verify=False, url=url, data=myfile, headers=headers)
print(response.text)
except Exception as e:
print "Exception:", e
Error:
"Multipart form parse error - Invalid boundary in multipart: None"
What is right way to post the file? Thanks
requests.version '2.10.0'
Removed 'content-type' from the headers, now it works
try:
headers = {
'authorization': "Basic ZXNlbnRpcmVcYdddddddddddddd",
'cache-control': "no-cache",
}
myfile = {"file": ("filexxx", open(filepath, "rb"))}
response = requests.request("POST", verify=False, url=url, data=myfile, headers=headers)
print(response.text)
except Exception as e:
print "Exception:", e
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With