4

What is the equivalent of:

curl --data-binary @myjarfile.jar localhost:10000/acceptjar

In python with the requests api?

The .jar file is a binary file that gets "posted" to a server that expects to receive the jar file.

1
  • what does this do in r provide function example Commented Jun 29, 2015 at 6:00

1 Answer 1

6

This doesn't handle errors, but should post a file to a server as an octet stream:

import requests
res = requests.post(url='http://example.com/post',
                    data=open('example.file', 'rb'),
                    headers={'Content-Type': 'application/octet-stream'})
Sign up to request clarification or add additional context in comments.

2 Comments

It is also possible to pass the file object as data without reading from it first.
I was stuck trying out files option in python. That never worked. This is the right method.

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.