【发布时间】:2021-12-08 09:48:21
【问题描述】:
我正在尝试使用 python 向我的烧瓶网络服务器请求图像,但无法正常工作。
使用 cURL 很简单:
curl -XPOST -F "file=@image.jpg" 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(并且是我想要返回的)。
任何帮助将不胜感激,谢谢。
【问题讨论】:
标签: python flask python-requests