0

I am trying to send a binary file (.parquet) to a web server via HTTP POST request. The python code below works flawlessly:

url = 'http://localhost/update/id'
f = open('/home/dev/datafiles/file.parquet', 'rb')
files = {'file': f}
try:
    r = requests.post(url, files=files)
finally:
    f.close()

However, using cURL, I could not get it to work, resulting in error 400: Bad Request. The cURL command that I am trying is:

curl -X POST \
-H 'Content-Type: multipart/form-data' \
--data-binary @/home/dev/datafiles/file.parquet \
http://localhost/update/id

I tried with -F instead of -X POST and with -d instead of --data-binary already, but I am getting 400 no matter what.

Using curlify to extract the cURL command from the PreparedRequest object in Python, I get:

curl -X POST \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Accept: */*' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 85705' \
-H 'Content-Type: multipart/form-data; boundary=c732fde3afb641d2ba5010efc59497bd' \
-H 'User-Agent: python-requests/2.18.4' \
-d '--c732fde3afb641d2ba5010efc59497bd Content-Disposition: form-data; name="file"; filename="file.parquet" [binary_content_goes_here] --c732fde3afb641d2ba5010efc59497bd--' \
http://localhost/update/id

But I was not able to get it to work, even when replacing the -d part with -d @/home/dev/datafiles/file.parquet or --data-binary @/home/dev/datafiles/file.parquet.

Am I missing something?

holypriest
  • 191
  • 8

0 Answers0