I am trying to translate the following curl command into a python request API call:
curl --header "Content-Type: application/octet-stream" --request PUT --data-binary @content.tar.gz <upload_url>
I have got as far as doing:
import requests
data = open("content.tar.gz", "rb").read()
response = requests.put(
<upload_url>,
headers={"Content-Type": "application/octet-stream"},
data=data
)
Although the status code from the above call is 200 the content.tar.gz file does not seem to get uploaded while the curl command works flawlessly.
I have looked at many different questions regarding translating curl commands to python requests but have not found any reasons why this should not work when the curl command does.
Hope you may be able to give me some pointers on what I am doing wrong.
curlwith verbose option, to see what's actually going on, becausecurlhandles some HTTP complexity behind the scenes. If you have access to logs on server side, inspecting them could help. Otherwise your code looks OK. I tried it against this simplehttpserver supporting PUT: gist.github.com/fabiand/5628006 and it worked.