Skip to content
New issue

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

上传文件时的中文文件名 #292

Closed
helloqiu opened this issue May 6, 2018 · 0 comments
Closed

上传文件时的中文文件名 #292

helloqiu opened this issue May 6, 2018 · 0 comments
Assignees
Labels

Comments

@helloqiu
Copy link
Collaborator

helloqiu commented May 6, 2018

  • 对 Bug 的描述

    • 当前行为:
      上传文件时如果文件名为中文会返回 41005: media data missing hint
    • 正确的行为:
      能正确上传不报错。
  • 环境

    • 平台:macOS
    • WeRoBot 版本号:1.4.0
    • Python 版本:all
  • 复现代码或 repo 链接

from werobot import WeRoBot
from werobot.config import Config
from werobot.replies import ImageReply

my_config = Config() # my configuration is not showed here

robot = WeRoBot(config=my_config)
robot.logger.setLevel('INFO')


@robot.text
def test(msg):
    robot.logger.info(msg)
    with open('照桥心美.png', 'rb') as f:
        r = robot.client.upload_media(media_file=f, media_type='image')
    robot.logger.info(r)
    return ImageReply(
        message=msg,
        media_id=r['media_id']
    )

robot.run()

# 请在这里给出 bug 的复现代码。如有必要,可以创建一个复现 repo 并将链接粘贴到这里。
  • 复现步骤
    运行以上代码,中文名会报错,英文名不会。

  • 其他信息

requests的相关 issue:
psf/requests#3085

@helloqiu helloqiu added the bug label May 6, 2018
@helloqiu helloqiu self-assigned this May 6, 2018
helloqiu added a commit that referenced this issue May 6, 2018
whtsky pushed a commit that referenced this issue May 9, 2018
* fix(client): urlencode file name

#292

* refactor(client): move encoding filename to post method

* test(client): split client.post test into unit test and integration test

* test(windows): set PYTHONIOENCODING to utf-8

* fix(client): check name attribute before urlencoding filename

* test(client): create a fake picture file for related tests

* style(client): correct coding style

* fix(client): urlencode filenames for all files in "files" before upload

* refactor(client): refactor urlencode to reduce block nest and make it more pythonic

* style(client): fix client style problem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant