Inputfile encode filenames (#1086)

* Unitest to recreate issue #1083

* InputFile: Encode unicode filenames

Fixes #1083
This commit is contained in:
Noam Meltzer 2018-04-25 23:13:00 +03:00 committed by GitHub
parent 1ec12343f0
commit 38d6f4d9f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -86,6 +86,10 @@ class InputFile(object):
else:
self.mimetype = DEFAULT_MIME_TYPE
if sys.version_info < (3,):
if isinstance(self.filename, unicode): # flake8: noqa pylint: disable=E0602
self.filename = self.filename.encode('utf-8', 'replace')
@property
def headers(self):
""":obj:`dict`: Headers."""

View file

@ -27,7 +27,7 @@ from telegram import Sticker, TelegramError, PhotoSize, InputFile
@pytest.fixture(scope='function')
def photo_file():
f = open('tests/data/telegram.jpg', 'rb')
f = open(u'tests/data/telegram.jpg', 'rb')
yield f
f.close()