nickoala / telepot

Python framework for Telegram Bot API
MIT License
2.42k stars 474 forks source link

send file with non-ACSII filename #59

Closed Toofarto closed 8 years ago

Toofarto commented 8 years ago

Error will occur when using sendDocument/sendAudio/...etc with non-ASCII filename. The underlying cause is that the function format_header_param() in "requests/packages/urllib3/fields.py" (from library requests) is using an old way "RFC 2231" to handle non-ASCII character for the content-disposition of multipart/form-data. However, telegram bot API seem aborted this way and accept the utf-8 charater directly.

The way I solve this issue is changing the body of format_header_param() from

...
value = email.utils.encode_rfc2231(value, 'utf-8') 
value = '%s*=%s' % (name, value)
...

to

value = '%s=%s' % (name, value)

Obviously, it is not a perfect way to tackle the problem since it may affect other process to use library requests

nickoala commented 8 years ago

This may be related to issue #32, which will be my priority from now on. Let's see how it ends up.