Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of curl --data-binary in python?

Tags:

python

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.

like image 420
Rolando Avatar asked Sep 11 '25 01:09

Rolando


1 Answers

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'})
like image 172
Alex Taylor Avatar answered Sep 12 '25 16:09

Alex Taylor