skip to Main Content

I have written python to broadcast message to ma telegram channel. but now i am getting

error 1
  443 too many connections, ssl problem, i 

error 2
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

Source code:

token = 'ccccccc';
channelName = '@ccccc';
message = "test";

url = 'https://api.telegram.org/bot' + token + '/sendMessage?chat_id=' + channelName + '&text=' + message;
result = requests.get ( url, verify=False );
print ( result.content );

3

Answers


  1. Chosen as BEST ANSWER
    Traceback (most recent call last):
      File "D:Python37libsite-packagesrequestspackagesurllib3connectionpool.py", line 544, in urlopen
        body=body, headers=headers)
      File "D:Python37libsite-packagesrequestspackagesurllib3connectionpool.py", line 341, in _make_request
        self._validate_conn(conn)
      File "D:Python37libsite-packagesrequestspackagesurllib3connectionpool.py", line 761, in _validate_conn
        conn.connect()
      File "D:Python37libsite-packagesrequestspackagesurllib3connection.py", line 238, in connect
        ssl_version=resolved_ssl_version)
      File "D:Python37libsite-packagesrequestspackagesurllib3utilssl_.py", line 279, in ssl_wrap_socket
        return context.wrap_socket(sock, server_hostname=server_hostname)
      File "D:Python37libssl.py", line 412, in wrap_socket
        session=session
      File "D:Python37libssl.py", line 850, in _create
        self.do_handshake()
      File "D:Python37libssl.py", line 1108, in do_handshake
        self._sslobj.do_handshake()
    ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "D:Python37libsite-packagesrequestsadapters.py", line 370, in send
        timeout=timeout
      File "D:Python37libsite-packagesrequestspackagesurllib3connectionpool.py", line 597, in urlopen
        _stacktrace=sys.exc_info()[2])
      File "D:Python37libsite-packagesrequestspackagesurllib3utilretry.py", line 245, in increment
        raise six.reraise(type(error), error, _stacktrace)
      File "D:Python37libsite-packagesrequestspackagesurllib3packagessix.py", line 309, in reraise
        raise value.with_traceback(tb)
      File "D:Python37libsite-packagesrequestspackagesurllib3connectionpool.py", line 544, in urlopen
        body=body, headers=headers)
      File "D:Python37libsite-packagesrequestspackagesurllib3connectionpool.py", line 341, in _make_request
        self._validate_conn(conn)
      File "D:Python37libsite-packagesrequestspackagesurllib3connectionpool.py", line 761, in _validate_conn
        conn.connect()
      File "D:Python37libsite-packagesrequestspackagesurllib3connection.py", line 238, in connect
        ssl_version=resolved_ssl_version)
      File "D:Python37libsite-packagesrequestspackagesurllib3utilssl_.py", line 279, in ssl_wrap_socket
        return context.wrap_socket(sock, server_hostname=server_hostname)
      File "D:Python37libssl.py", line 412, in wrap_socket
        session=session
      File "D:Python37libssl.py", line 850, in _create
        self.do_handshake()
      File "D:Python37libssl.py", line 1108, in do_handshake
        self._sslobj.do_handshake()
    requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "D:worksPythonSampledummy.py", line 8, in <module>
        post('https://api.telegram.org/bot' + token + '/sendMessage?chat_id=' + channelName + '&text=' + qt(message) + '&parse_mode=markdown')
      File "D:Python37libsite-packagesrequestsapi.py", line 109, in post
        return request('post', url, data=data, json=json, **kwargs)
      File "D:Python37libsite-packagesrequestsapi.py", line 50, in request
        response = session.request(method=method, url=url, **kwargs)
      File "D:Python37libsite-packagesrequestssessions.py", line 465, in request
        resp = self.send(prep, **send_kwargs)
      File "D:Python37libsite-packagesrequestssessions.py", line 573, in send
        r = adapter.send(request, **kwargs)
      File "D:Python37libsite-packagesrequestsadapters.py", line 415, in send
        raise ConnectionError(err, request=request)
    requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
    

  2. You should use the POST method instead of GET.

    Try this;

    from requests import post
    from urllib.parse import quote as qt
    
    
    token = 'your-token-here'
    channelName = '@channel_id'
    message = "test message"
    
    post('https://api.telegram.org/bot' + token + '/sendMessage?chat_id=' + channelName + '&text=' + qt(message) + '&parse_mode=markdown')
    
    Login or Signup to reply.
  3. This can be in two cases:

    1. The telegram was blocked in your country. Use a VPN to prevent these errors.
    2. This bot was run as pulling, so you can try to connect as the second bot by same token – Telegram aborts this connection. Try to use greater delay time in the first instance of a bot or use webhooks.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search