使用Python请求中的POST表单数据上载Image
发布时间:2020-12-20 10:31:46 所属栏目:Python 来源:网络整理
导读:我正在使用微信API … 在这里,我将使用此API将图像上传到wechat的服务器 http://admin.wechat.com/wiki/index.php?title=Transferring_Multimedia_Files url = 'http://file.api.wechat.com/cgi-bin/media/upload?access_token=%stype=image'%access_token f
我正在使用微信API …
在这里,我将使用此API将图像上传到wechat的服务器 http://admin.wechat.com/wiki/index.php?title=Transferring_Multimedia_Files url = 'http://file.api.wechat.com/cgi-bin/media/upload?access_token=%s&type=image'%access_token files = { 'file': (filename,open(filepath,'rb'),'Content-Type': 'image/jpeg','Content-Length': l } r = requests.post(url,files=files) 我无法发布数据 解决方法
来自wechat api doc:
curl -F media=@test.jpg "http://file.api.wechat.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE" 将上面的命令翻译为python: import requests url = 'http://file.api.wechat.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE' files = {'media': open('test.jpg','rb')} requests.post(url,files=files) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |