简体   繁体   中英

errors from api when using python requests module for file upload

when i make the following request:

curl -X POST http://localhost:8080/endpoint \
  -F "file=filepath/example.zip" \
  -H "Content-Type: multipart/form-data"

everything works fine. However, when i try to do the same in python:

import requests

url = "http://localhost:8080/endpoint"

files = {"file": open("example.zip", "rb")}
headers = {"Content-Type": "multipart/form-data"}

r = requests.post(url, files=files, headers=headers)

the api gives me an error. are these two code snippets not equivalent? thanks

the issue was this:

multipart data POST using python requests: no multipart boundary was found

it seems as though setting

headers = {"Content-Type": "multipart/form-data"}

caused the issue. i removed it and it works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM