Forums

Help with Bot Telegram Code on Python

Hello. I'm getting an error that i don't know how to solve. Can you please help?

2018-11-13 10:43:31,543 (util.py:64 PollingThread) ERROR - TeleBot: "ReadTimeout occurred, args=(ReadTimeoutError("HTTPSConnectionPool(host='api.telegra m.org', port=443): Read timed out. (read timeout=30)",),) Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/connectionpool.py", line 386, in _make_request six.raise_from(e, None) File "<string>", line 2, in raise_from File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/connectionpool.py", line 382, in _make_request httplib_response = conn.getresponse() File "/usr/lib/python3.6/http/client.py", line 1331, in getresponse response.begin() File "/usr/lib/python3.6/http/client.py", line 297, in begin version, status, reason = self._read_status() File "/usr/lib/python3.6/http/client.py", line 258, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/usr/lib/python3.6/socket.py", line 586, in readinto return self._sock.recv_into(b) File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 291, in recv_into raise timeout('The read operation timed out') socket.timeout: The read operation timed out During handling of the above exception, another exception occurred: self._raise_timeout(err=e, url=url, timeout_value=read_timeout)

Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/requests/adapters.py", line 423, in send timeout=timeout File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/connectionpool.py", line 649, in urlopen _stacktrace=sys.exc_info()[2]) File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/util/retry.py", line 347, in increment raise six.reraise(type(error), error, _stacktrace) File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/packages/six.py", line 686, in reraise raise value File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/connectionpool.py", line 388, in _make_request self._raise_timeout(err=e, url=url, timeout_value=read_timeout) File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/connectionpool.py", line 308, in _raise_timeout raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value) requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=30)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "./telebot/util.py", line 58, in run task(args, kwargs) File "./telebot/init.py", line 159, in retrieve_updates updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout) File "./telebot/__init.py", line 129, in get_updates json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates) File "./telebot/apihelper.py", line 175, in get_updates return _make_request(token, method_url, params=payload) File "./telebot/apihelper.py", line 54, in _make_request timeout=(connect_timeout, read_timeout), proxies=proxy) File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 488, in request resp = self.send(prep, send_kwargs) File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 609, in send r = adapter.send(request, *kwargs) File "/usr/local/lib/python3.6/dist-packages/requests/adapters.py", line 499, in send raise ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=30) " ERROR:root:HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=30) Internet error! Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/connectionpool.py", line 386, in _make_request six.raise_from(e, None) File "<string>", line 2, in raise_from File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/connectionpool.py", line 382, in _make_request httplib_response = conn.getresponse() File "/usr/lib/python3.6/http/client.py", line 1331, in getresponse response.begin() File "/usr/lib/python3.6/http/client.py", line 297, in begin version, status, reason = self._read_status() File "/usr/lib/python3.6/http/client.py", line 258, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/usr/lib/python3.6/socket.py", line 586, in readinto return self._sock.recv_into(b) File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 291, in recv_into raise timeout('The read operation timed out') socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/requests/adapters.py", line 423, in send timeout=timeout File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/connectionpool.py", line 649, in urlopen _stacktrace=sys.exc_info()[2]) File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/util/retry.py", line 347, in increment raise six.reraise(type(error), error, _stacktrace) File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/packages/six.py", line 686, in reraise raise value File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/connectionpool.py", line 388, in _make_request self._raise_timeout(err=e, url=url, timeout_value=read_timeout) File "/usr/local/lib/python3.6/dist-packages/requests/packages/urllib3/connectionpool.py", line 308, in _raise_timeout raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value) requests.packages.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=30)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/javiolol/botpolePikachu.py", line 1493, in <module> bot.polling(none_stop=True) File "./telebot/init.py", line 264, in polling self.threaded_polling(none_stop, interval, timeout) File "./telebot/__init.py", line 287, in __threaded_polling polling_thread.raise_exceptions() File "./telebot/util.py", line 77, in raise_exceptions six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2]) File "/usr/local/lib/python3.6/dist-packages/six.py", line 686, in reraise raise value File "./telebot/util.py", line 58, in run task(args, kwargs) File "./telebot/init.py", line 159, in retrieve_updates updates = self.get_updates(offset=(self.last_update_id + 1), timeout=timeout) File "./telebot/__init.py", line 129, in get_updates json_updates = apihelper.get_updates(self.token, offset, limit, timeout, allowed_updates) File "./telebot/apihelper.py", line 175, in get_updates return _make_request(token, method_url, params=payload) File "./telebot/apihelper.py", line 54, in _make_request timeout=(connect_timeout, read_timeout), proxies=proxy) File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 488, in request resp = self.send(prep, send_kwargs) File "/usr/local/lib/python3.6/dist-packages/requests/sessions.py", line 609, in send r = adapter.send(request, *kwargs) File "/usr/local/lib/python3.6/dist-packages/requests/adapters.py", line 499, in send raise ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): Read timed out. (read timeout=30)


Here the code:

import telebot # Librería de la API del bot.

bot = telebot.TeleBot('-)

def listener(mensajes):

for m in mensajes:

    persona = "@" + str(m.from_user.username)
    persona_id = m.from_user.id

    if m.content_type == 'photo':
        if persona == '@Mrgorkaa':
            print( persona, ' - ', persona_id, ' - ', 'Intento enviar una imagen, pero está bloqueado.')
            bot.send_message(11111, persona + " Intento enviar una foto al canal, y es un usuario bloqueado.")
            bot.send_message(11111, persona + " Intento enviar una foto al canal, y es un usuario bloqueado.")
        else:
            print( persona, ' - ', persona_id, ' - ', 'No está bloqueada.')
            bot.forward_message(-1001141618129,-1001121187619,m.message_id)

bot.set_update_listener(listener)

bot.polling(none_stop=True)

Check out the very first part of our blogpost about making a telegram bot. You need to setup the proxy stuff if you are using a free account.

Thank you, but new error appears:

Traceback (most recent call last): File "/home/javiolol/bottangela.py", line 14, in <module> telepot.api._pools = {'default': urllib3.ProxyManager(proxy_url=proxy_url, num_pools=3, maxsize=10, retries=False, timeout=30),} NameError: name 'urllib3' is not defined

Nvm.

i cant find how can i get user id of people on telepot

It's probably best to look at the Telegram API docs for information like that.