R
R
Remasten2020-05-08 16:01:23
Python
Remasten, 2020-05-08 16:01:23

What is the mistake when writing a telegram bot in Python?

I decided to write a bot in telegram:
the whole code:

import telebot
import config
bot = telebot.TeleBot(config.TOKEN)

@bot.message_handler(content_types=['text'])
def lalala(message):
bot.send_message(message.chat.id, message.text)

#RUN
bot .polling(none_stop=True)

I inserted the token, don't worry, but it gives a long error:
2020-05-08 15:59:34,389 (util.py:68 PollingThread) ERROR - TeleBot: "ConnectTimeout occurred, args=(MaxRetryError("HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot1160431424:AAHIcuMyVJnDrfftQyk7_G3qmHpwamAPgfk/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(, 'Connection to api.telegram.org timed out. (connect timeout=3.5)'))")),)
Traceback (most recent call last):
File "C:\Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 159, in _new_conn
conn = connection.create_connection(
File "C:\Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\connection.py", line 84,in create_connection
raise err
File "C:\Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\connection.py", line 74, in create_connection
sock.connect(sa)
socket.timeout : timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3 \connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "C:\Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py" , line 381, in _make_request
self._validate_conn(conn)
File "C:\Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 976, in _validate_conn
conn.connect()
File "C:\Users \Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 308, in connect
conn = self._new_conn()
File "C:\Users\Schil\AppData \Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connection.py", line 164, in _new_conn
raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (, 'Connection to api.telegram.org timed out .(connect timeout=3.5)')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 439, in send
resp = conn.urlopen(
File "C:\ Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 724, in urlopen
retries = retries.increment(
File "C:\Users\Schil\AppData \Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\retry.py", line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot1160431424:AAHIcuMyVJnDrfftQyk7_G3qmHpwamAPgfk/getUpdates?offset=1&timeout=20 (Caused by ConnectTimeoutError(, 'Connection to api.telegram.org timed out.(connect timeout=3.5)'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\Schil\AppData\Local\Programs \Python\Python38-32\lib\site-packages\telebot\util.py", line 62, in run
task(*args, **kwargs)
File "C:\Users\Schil\AppData\Local\Programs\Python \Python38-32\lib\site-packages\telebot\__init__.py", line 281, in __retrieve_updates
updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout)
File "C:\Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 251, in get_updates
json_updates = apihelper.get_updates(self.token, offset , limit, timeout, allowed_updates)
File "C:\Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 199, in get_updates
return _make_request(token , method_url, params=payload)
File "C:\Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 62, in _make_request
result = _get_req_session( ).request(method, request_url, params=params, files=files,
File "C:\Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py",line 530, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Schil\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 643, in send
r = adapter.send(request, **kwargs)

This is not the entire text of the error.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Engeftroll, 2020-05-08
@Remasten

I faced such problem. Telegram bots do not work from the Russian Federation, the same blocking.
Use VPN. I used ProtonVPN and everything worked great.
This is indicated by the first part of the error (Caused by ConnectTimeoutError(, 'Connection to api.telegram.org timed out. (connect timeout=3.5)'))")),).

S
Sergey Karbivnichy, 2020-05-08
@hottabxp

Roskomnadzor blocks Telegram. You need to use a proxy. Better yet, use a search engine. And here such questions are asked every day!
PS: I would generally ban for a year users who ask a question with the "telegram" tag and in whose question there is a line - "Connection to api.telegram.org timed out".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question