Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Use system proxy if set #57

Open
Unin777 opened this issue Nov 1, 2018 · 5 comments
Open

Use system proxy if set #57

Unin777 opened this issue Nov 1, 2018 · 5 comments

Comments

@Unin777
Copy link

Unin777 commented Nov 1, 2018

Hi

First of all, thank you Ritiek for your great project, I really love it,
yesterday I started to work with this bot, and I have my but running on VPS, and everything works find, except one thing.

As you guys may know Telegram is banned in some countries, and users from those countries use VPN in order to use the telegram. However, I gave this but to a friend of mine which lives in a country where Telegram is banned, and he got errors from the console, which indicated that couldn't establish a connection. Notice that he also had a VPN running, but still had the same problem. I wanna know is there a way around this? As I'm a beginner in Python, I can use your help to improve my rat.

`Traceback (most recent call last):
File "site-packages\telepot_init_.py", line 1183, in get_from_telegram_server
File "site-packages\telepot_init_.py", line 1000, in getUpdates
File "site-packages\telepot_init_.py", line 491, in _api_request
File "site-packages\telepot\api.py", line 154, in request
File "site-packages\urllib3\request.py", line 150, in request_encode_body
File "site-packages\urllib3\poolmanager.py", line 323, in urlopen
File "site-packages\urllib3\connectionpool.py", line 667, in urlopen
File "site-packages\urllib3\connectionpool.py", line 667, in urlopen
File "site-packages\urllib3\connectionpool.py", line 667, in urlopen
File "site-packages\urllib3\connectionpool.py", line 638, in urlopen
File "site-packages\urllib3\util\retry.py", line 398, in increment
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot716427487:AAHi_7vtN8i7m8ET_E7vukMGaFETqo7FHh4/getUpdates (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x061944D0>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))
Traceback (most recent call last):
File "site-packages\urllib3\connection.py", line 159, in _new_conn
File "site-packages\urllib3\util\connection.py", line 57, in create_connection
File "socket.py", line 748, in getaddrinfo
socket.gaierror: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "site-packages\urllib3\connectionpool.py", line 600, in urlopen
File "site-packages\urllib3\connectionpool.py", line 343, in _make_request
File "site-packages\urllib3\connectionpool.py", line 839, in _validate_conn
File "site-packages\urllib3\connection.py", line 301, in connect
File "site-packages\urllib3\connection.py", line 168, in _new_conn
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x05C61F90>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "site-packages\telepot_init_.py", line 1183, in get_from_telegram_server
File "site-packages\telepot_init_.py", line 1000, in getUpdates
File "site-packages\telepot_init_.py", line 491, in _api_request
File "site-packages\telepot\api.py", line 154, in request
File "site-packages\urllib3\request.py", line 150, in request_encode_body
File "site-packages\urllib3\poolmanager.py", line 323, in urlopen
File "site-packages\urllib3\connectionpool.py", line 667, in urlopen
File "site-packages\urllib3\connectionpool.py", line 667, in urlopen
File "site-packages\urllib3\connectionpool.py", line 667, in urlopen
File "site-packages\urllib3\connectionpool.py", line 638, in urlopen
File "site-packages\urllib3\util\retry.py", line 398, in increment
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot716427487:AAHi_7vtN8i7m8ET_E7vukMGaFETqo7FHh4/getUpdates (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x05C61F90>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))
Traceback (most recent call last):
File "site-packages\urllib3\connection.py", line 159, in _new_conn
File "site-packages\urllib3\util\connection.py", line 57, in create_connection
File "socket.py", line 748, in getaddrinfo
socket.gaierror: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "site-packages\urllib3\connectionpool.py", line 600, in urlopen
File "site-packages\urllib3\connectionpool.py", line 343, in _make_request
File "site-packages\urllib3\connectionpool.py", line 839, in _validate_conn
File "site-packages\urllib3\connection.py", line 301, in connect
File "site-packages\urllib3\connection.py", line 168, in _new_conn
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x061E9BF0>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "site-packages\telepot_init_.py", line 1183, in get_from_telegram_server
File "site-packages\telepot_init_.py", line 1000, in getUpdates
File "site-packages\telepot_init_.py", line 491, in _api_request
File "site-packages\telepot\api.py", line 154, in request
File "site-packages\urllib3\request.py", line 150, in request_encode_body
File "site-packages\urllib3\poolmanager.py", line 323, in urlopen
File "site-packages\urllib3\connectionpool.py", line 667, in urlopen
File "site-packages\urllib3\connectionpool.py", line 667, in urlopen
File "site-packages\urllib3\connectionpool.py", line 667, in urlopen
File "site-packages\urllib3\connectionpool.py", line 638, in urlopen
File "site-packages\urllib3\util\retry.py", line 398, in increment
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot716427487:AAHi_7vtN8i7m8ET_E7vukMGaFETqo7FHh4/getUpdates (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x061E9BF0>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed'))`

@mvrozanti
Copy link
Owner

mvrozanti commented Nov 2, 2018

The requests need to go through the VPN proxy. We could add something like this. Is this the same error you get when trying to connect without a proxy?

@mvrozanti mvrozanti changed the title Found a new problem Use system proxy if set Nov 2, 2018
@Unin777
Copy link
Author

Unin777 commented Nov 2, 2018

The requests need to go through the VPN proxy. We could add something like this. Is this the same error you get when trying to connect without a proxy?

Yes it is, it is also the same error when you are not connected to the internet

@mvrozanti
Copy link
Owner

As per a quick fix, you can set the following lines before instantiating the Bot object:

proxy_url = "http://proxy.server:3128"
telepot.api._pools = {
    'default': urllib3.ProxyManager(proxy_url=proxy_url, num_pools=3, maxsize=10, retries=False, timeout=30),
}
telepot.api._onetime_pool_spec = (urllib3.ProxyManager, dict(proxy_url=proxy_url, num_pools=1, maxsize=1, retries=False, timeout=30))

Change the proxy url/port and you should be good to go. Tell me how it goes

@Unin777
Copy link
Author

Unin777 commented Nov 2, 2018

As per a quick fix, you can set the following lines before instantiating the Bot object:

proxy_url = "http://proxy.server:3128"
telepot.api._pools = {
    'default': urllib3.ProxyManager(proxy_url=proxy_url, num_pools=3, maxsize=10, retries=False, timeout=30),
}
telepot.api._onetime_pool_spec = (urllib3.ProxyManager, dict(proxy_url=proxy_url, num_pools=1, maxsize=1, retries=False, timeout=30))

Change the proxy url/port and you should be good to go. Tell me how it goes

Thanks for your quick response, I wanna ask, how should I set the proxy url? I mean from where I can get a proxy server? Is there a way my bot can use the VPN that the user is using?

As to my knowledge, I dont know a free proxy server which is stable enough to use in the rat

@mvrozanti
Copy link
Owner

Yes, there is a way to connect to a VPN that is not on your local computer. For this, you need a proxy server running publicly. The proxy_url variable would then contain the address/port of that server.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants