When uploading a file via post to an API endpoint, python requests.post always sets the content-length to 0. In my case, a proprietary API endpoint rejects the upload with an error 500.
heads = { 'Authoriziation': 'Bearer ...'
'Content-Type': 'multipart/form-data',
'Accept': 'application/json'
}
files = { 'file': ('dummpy.pdf', open(filename, 'rb'), 'application/pdf') }
ret = requests.post('https://my.apiendpoint.io/jadajadajada',
files=files, headers=heads)
Even if I prepare the request and try to overwrite the Content-Length, it's either missing or zero, but never the actual value, which the API endpoint requires.
Any ideas how to fix this? Or is this a bug in python-requests?
$ python3 --version
Python 3.8.10
$ pip3 list|grep requests
requests 2.23.0
Workaround: Upload the file with pycurl.