1

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.

3
  • How large is the file you are trying to upload? Commented Apr 14, 2021 at 14:22
  • 1.5 K in size not very large at all. Commented Apr 14, 2021 at 15:35
  • I though maybe you needed something like this, if the file is too large: stackoverflow.com/a/35784072/7109330 Maybe you can check curl with verbose option, to see what's actually going on, because curl handles 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. Commented Apr 14, 2021 at 15:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.