1

I would like to transpose the curl command (which upload a local file to rackspace)

curl -X PUT -T screenies/hello.jpg -D - \
-H "X-Auth-Token: fc81aaa6-98a1-9ab0-94ba-aba9a89aa9ae" \
https://storage101.dfw1.clouddrive.com/v1/CF_xer7_343/images/hello.jpg

to python requests. So far I have:

url = 'http://storage.clouddrive.com/v1/CF_xer7_343/images/hello.jpg'
headers = {'X-Auth-Token': 'fc81aaa6-98a1-9ab0-94ba-aba9a89aa9ae'}
request = requests.put(url, headers=headers, data={})

where do I specify I want to upload screenies/hello.jpg?

I understand -T in curl represents 'to FTP server', but I have searched the requests's github but cannot find mention of FTP.

1

1 Answer 1

1

No, -T just means 'upload this file', which can be used with FTP but is not limited to that.

You can just upload the file data as the data parameter:

with open('screenies/hello.jpg', 'rb') as image:
    request = requests.put(url, headers=headers, data=image)

where data will read and upload the image data for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.