Skip to content

Can't send document with nonascii caption #1159

@cheshire-mouse

Description

@cheshire-mouse

When I try to send document with a caption, containing nonascii characters, exception is raised
If I change (or remove) the caption, everything works fine

Steps to reproduce

def on_cmd_test(bot, update):
    f=open('/tmp/test.txt','rb')
    bot.send_document(update.message.chat_id,document=f,caption=u'Привет')
    f.close
    return

Expected behaviour

Document is sent

Actual behaviour

Exception:


2018-07-12 19:28:50,139 telegram.ext.dispatcher ERROR An uncaught error was raised while processing the update
Traceback (most recent call last):
  File "/opt/draw-gpx-bot/lib/telegram/ext/dispatcher.py", line 279, in process_update
    handler.handle_update(update, self)
  File "/opt/draw-gpx-bot/lib/telegram/ext/commandhandler.py", line 173, in handle_update
    return self.callback(dispatcher.bot, update, **optional_args)
  File "./drawgpxbot.py", line 193, in on_cmd_test
    bot.send_document(update.message.chat_id,document=f,caption=u'Привет')
  File "/opt/draw-gpx-bot/lib/telegram/bot.py", line 60, in decorator
    result = func(self, *args, **kwargs)
  File "/opt/draw-gpx-bot/lib/telegram/bot.py", line 85, in decorator
    result = self._request.post(url, data, timeout=kwargs.get('timeout'))
  File "/opt/draw-gpx-bot/lib/telegram/utils/request.py", line 270, in post
    'POST', url, body=data.to_form(), headers=data.headers, **urlopen_kwargs)
  File "/opt/draw-gpx-bot/lib/telegram/files/inputfile.py", line 120, in to_form
    form_boundary, 'Content-Disposition: form-data; name="%s"' % name, '', str(value)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)

Configuration

Operating System:

Ubuntu 16.04.4 LTS

Version of Python, python-telegram-bot & dependencies:
$ python -m telegram

python-telegram-bot 10.1.0
certifi 2018.04.16
future 0.16.0
Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions