We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用 requests 可以成功上传英文文件名的文件,但不能上传文件名包含中文的情况。 能否给出使用 requests 上传文件名包含中文的示例?
我目前的做法: f = open(u'测试.txt', 'rb') url = '''https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=file''' % ac_token files = {'file': ('测试.txt', f)} r = requests.post(url, files=files)
f = open(u'测试.txt', 'rb')
url = '''https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=file''' % ac_token
files = {'file': ('测试.txt', f)}
r = requests.post(url, files=files)
返回的是 {u'errcode': 44001, u'errmsg': u'empty media data, hint: [ ], more info at https://open.work.weixin.qq.com/devtool/query?e=44001'}
{u'errcode': 44001, u'errmsg': u'empty media data, hint: [ ], more info at https://open.work.weixin.qq.com/devtool/query?e=44001'}
看起来是 requests 将 Content-Disposition 部分写为了: Content-Disposition: form-data; name="file"; filename*=utf-8''%E6%B5%8B%E8%AF%95.txt
Content-Disposition: form-data; name="file"; filename*=utf-8''%E6%B5%8B%E8%AF%95.txt
使用 API 测试页面 可以成功上传中文文件名的文件,看到的 Request Payload 为: Content-Disposition: form-data; name="media"; filename="测试.txt"
Content-Disposition: form-data; name="media"; filename="测试.txt"
The text was updated successfully, but these errors were encountered:
python 要使用中文,需要在 文件开头加 #coding=utf-8 具体可百度
Sorry, something went wrong.
No branches or pull requests
使用 requests 可以成功上传英文文件名的文件,但不能上传文件名包含中文的情况。
能否给出使用 requests 上传文件名包含中文的示例?
我目前的做法:
f = open(u'测试.txt', 'rb')
url = '''https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=file''' % ac_token
files = {'file': ('测试.txt', f)}
r = requests.post(url, files=files)
返回的是
{u'errcode': 44001, u'errmsg': u'empty media data, hint: [ ], more info at https://open.work.weixin.qq.com/devtool/query?e=44001'}
看起来是 requests 将 Content-Disposition 部分写为了:
Content-Disposition: form-data; name="file"; filename*=utf-8''%E6%B5%8B%E8%AF%95.txt
使用 API 测试页面 可以成功上传中文文件名的文件,看到的 Request Payload 为:
Content-Disposition: form-data; name="media"; filename="测试.txt"
The text was updated successfully, but these errors were encountered: