我正在尝试通过HTTP POST请求将二进制文件(.parquet)发送到Web服务器。下面的python代码完美无缺:
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()
然而,使用cURL,我无法使其工作,导致错误400:错误请求。我正在尝试的cURL命令是:
curl -X POST \
-H 'Content-Type: multipart/form-data' \
--data-binary @/home/dev/datafiles/file.parquet \
http://localhost/update/id
我尝试使用-F
代替-X POST
和-d
而不是--data-binary
,但无论如何我都会获得400分。
使用curlify
从Python中的PreparedRequest
对象中提取cURL命令,我得到:
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
但即使用-d
或-d @/home/dev/datafiles/file.parquet
替换--data-binary @/home/dev/datafiles/file.parquet
部分,我也无法使其发挥作用。
我错过了什么吗?