本文介绍了在python请求中使用POST表单数据上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用微信API ...在这里,我必须使用此API将图像上传到微信服务器 http://admin.wechat.com/wiki/index.php?title=Transferring_Multimedia_Files

I'm working with wechat APIs ...here I've to upload an image to wechat's server using this APIhttp://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)

我无法发布数据

推荐答案

来自微信api文档:

curl -F media=@test.jpg "http://file.api.wechat.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"

将上面的命令翻译成python:

Translate the command above to 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)

这篇关于在python请求中使用POST表单数据上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 17:45
查看更多