Skip to content

Commit a749acd

Browse files
authored
Update apihelper.py eternnoir#2
Merge Fixes # 684
1 parent 5935a37 commit a749acd

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

telebot/apihelper.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _get_req_session(reset=False):
3131
return util.per_thread('req_session', lambda: requests.session(), reset)
3232

3333

34-
def _make_request(token, method_name, method='get', params=None, files=None, base_url=API_URL):
34+
def _make_request(token, method_name, method='get', params=None, files=None):
3535
"""
3636
Makes a request to the Telegram API.
3737
:param token: The bot's API token. (Created with @BotFather)
@@ -41,12 +41,11 @@ def _make_request(token, method_name, method='get', params=None, files=None, bas
4141
:param files: Optional files.
4242
:return: The result parsed to a JSON dictionary.
4343
"""
44-
if base_url is None:
44+
if API_URL is None:
4545
request_url = "https://api.telegram.org/bot{0}/{1}".format(token, method_name)
4646
else:
47-
request_url = base_url.format(token, method_name)
47+
request_url = API_URL.format(token, method_name)
4848

49-
request_url = base_url.format(token, method_name)
5049
logger.debug("Request: method={0} url={1} params={2} files={3}".format(method, request_url, params, files))
5150
read_timeout = READ_TIMEOUT
5251
connect_timeout = CONNECT_TIMEOUT
@@ -105,13 +104,17 @@ def get_file(token, file_id):
105104

106105
def get_file_url(token, file_id):
107106
if FILE_URL is None:
108-
return "https://api.telegram.org/file/bot{0}/{1}".format(token, get_file(token, file_id).file_path)
107+
return "https://api.telegram.org/file/bot{0}/{1}".format(token, get_file(token, file_id)['file_path'])
109108
else:
110109
return FILE_URL.format(token, get_file(token, file_id)['file_path'])
111110

112111

113112
def download_file(token, file_path):
114-
url = FILE_URL.format(token, file_path)
113+
if FILE_URL is None:
114+
url = "https://api.telegram.org/file/bot{0}/{1}".format(token, file_path)
115+
else:
116+
url = FILE_URL.format(token, file_path)
117+
115118
result = _get_req_session().get(url, proxies=proxy)
116119
if result.status_code != 200:
117120
msg = 'The server returned HTTP {0} {1}. Response body:\n[{2}]' \

0 commit comments

Comments
 (0)