From f7fc538bd852824ed1ae52044480901ed3751572 Mon Sep 17 00:00:00 2001 From: Alex Kuznitsin Date: Mon, 30 Jan 2017 17:40:18 +0300 Subject: [PATCH] Non-ASCII chars for filename. Telegram doesn't accept rfc2231 styled filename. Using utf-8 directly. --- telebot/apihelper.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 7f04901..f5fe0ee 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -1,6 +1,10 @@ # -*- coding: utf-8 -*- import requests +try: + from requests.packages.urllib3 import fields +except ImportError: + fields = None import telebot from telebot import types from telebot import util @@ -29,6 +33,8 @@ def _make_request(token, method_name, method='get', params=None, files=None, bas logger.debug("Request: method={0} url={1} params={2} files={3}".format(method, request_url, params, files)) read_timeout = READ_TIMEOUT connect_timeout = CONNECT_TIMEOUT + if files and fields: + fields.format_header_param = _no_encode(fields.format_header_param) if params: if 'timeout' in params: read_timeout = params['timeout'] + 10 if 'connect-timeout' in params: connect_timeout = params['connect-timeout'] + 10 @@ -568,6 +574,15 @@ def _convert_markup(markup): return markup +def _no_encode(func): + def wrapper(key, val): + if key == 'filename': + return '{0}={1}'.format(key, val) + else: + return func(key, val) + return wrapper + + class ApiException(Exception): """ This class represents an Exception thrown when a call to the Telegram API fails.