我正在嘗試使用 python 向我的燒瓶網路服務器請求影像,但無法讓它作業。
使用 cURL 很簡單:
curl -XPOST -F "[email protected]" http://127.0.0.1:5001
但是在 python 中使用我的代碼:
import requests
with open("image.jpg", "rb") as a_file:
file_dict = {"image.jpg": a_file}
response = requests.post("http://127.0.0.1:5001", files=file_dict)
print(response.text)
print(response.status_code)
我只是得到回傳的站點的 HTML 和狀態 200。不是使用 cURL 回傳的 JSON(這是我想要回傳的)。
任何幫助將不勝感激,謝謝。
uj5u.com熱心網友回復:
您可以使用以下代碼
files = {'file': open('image.jpg', 'rb')}
r = requests.post('http://127.0.0.1:5001', files=files)
print(r.text)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/380537.html
上一篇:在Python/Flask應用程式中注冊的錯誤處理程式不起作用
下一篇:燒瓶應用程式帶來錯誤requests.exceptions.ConnectionErrorrequests.exceptions.ConnectionErrorMaxretriesexceededwi
