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.

nandac
  • 335
  • 3
  • 16
  • How large is the file you are trying to upload? – bagljas Apr 14 '21 at 14:22
  • 1.5 K in size not very large at all. – nandac Apr 14 '21 at 15:35
  • I though maybe you needed something like this, if the file is too large: https://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: https://gist.github.com/fabiand/5628006 and it worked. – bagljas Apr 14 '21 at 15:55

0 Answers0