【发布时间】:2019-11-15 07:15:18
【问题描述】:
我需要将本地图片上传到 URL。 我的 curl 请求看起来像:“curl -T 'my_picture' 'the_url'”。
我的目的是在 Python 中完成,我看到了,我必须使用:requests.put()。 我之前所做的一切都很好,但是这个功能给我带来了很多麻烦。
解决方案可能真的很简单,但我迷路了。
感谢您的帮助。
def apithree(urlupload):
url = urlupload
picture = Image.open("test.png")
headers = {"content-type": "multipart/form-data"}
response = requests.put(url, headers=headers, data=picture)
response = response.json()
print(response)
我尝试过的其他代码
def apithree(urlupload):
url = urlupload
files = {'image': open('test.png', 'rb')}
response = requests.post(url, data=files)
response = response.json()
print(response)
如果命令有效,输出应该是空的,但我总是有错误消息。
如有必要,我可以添加错误消息。
感谢您的帮助。
【问题讨论】:
标签: python-3.x api python-requests