使用请求(python 2.7)获取图像文件,然后使用post发送给服务器

2024-06-26 17:07:05 发布

您现在位置:Python中文网/ 问答频道 /正文

作为c按请求(python2.7)获取一个图像文件,然后用post方法发送到服务器?在

file = requests.get('http://site.com/immage.jpg')
requests.post('http://site2.com/, file=somefile')

如何将file转换为somefile?在


Tags: 方法服务器comhttpget图像文件sitepost
2条回答

使用响应的^{} attribute

resp = requests.get('http://site.com/immage.jpg')
requests.post('http://site2.com/, files=dict(file=resp.content))

我已经将下载的图片发布为multipart-encoded POST,字段名为file。这取决于您要发布到他们期望的字段名的确切应用程序。在

嗯,你留着吧。。。在

with open("somefile.jpg","wb") as f:
     f.write(file.content)

相关问题 更多 >