[英]python requests - post files multipart (http-status-code-400)
使用請求 2.26.0。 我想將文件發布到服務器。
下面使用 fastapi swagger ui 的結果代碼很好,但我從 python 代碼中得到:{"detail":"There was an error parsing the body"}
@router.post("/send/{email}")
async def send(email: str , files: List[UploadFile] = File(...)):
return user.send(email, files)
並發送 function:
def send(email: str, files):
for file in files:
with open(f'{file.filename}', "wb") as buffer:
shutil.copyfileobj(file.file, buffer)
print(email)
send_email(email, 'F:/PROJECT/scan2excel/input/ss.xls')
return {'file_name':'good'}
我從主要測試:
def upload_data(self, files_paths):
url = 'http://localhost:8000/user/send/'+str(self.email)
headers = {'Content-Type':'multipart/form-data; charset=utf-8; boundary=---- WebKitFormBoundary9JTSxAotKGVAuzQF'}
f={"file": ("filename", open('F:/PROJECT/scan2excel/input/1.jpg', "rb"), "image/jpeg")}
response = requests.post(url, files=f, headers=headers)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.