如何用Python在POST请求中上传图片作为表单数据?

2026-06-11 05:111阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计184个文字,预计阅读时间需要1分钟。

如何用Python在POST请求中上传图片作为表单数据?

我正在使用微信API...在这里,我将使用此API将图像上传到微信的服务器。URL:http://file.api.wechat.com/cgi-bin/media/upload?access_token=%25st

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

如何用Python在POST请求中上传图片作为表单数据?

url = '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 "file.api.wechat.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"

将上面的命令翻译为python:

import requests url = '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)

本文共计184个文字,预计阅读时间需要1分钟。

如何用Python在POST请求中上传图片作为表单数据?

我正在使用微信API...在这里,我将使用此API将图像上传到微信的服务器。URL:http://file.api.wechat.com/cgi-bin/media/upload?access_token=%25st

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

如何用Python在POST请求中上传图片作为表单数据?

url = '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 "file.api.wechat.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE"

将上面的命令翻译为python:

import requests url = '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)