edeng23 / binance-trade-bot

Automated cryptocurrency trading bot
GNU General Public License v3.0
7.95k stars 2.2k forks source link

Caused by ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1112: The handshake operation timed out') #438

Closed YangHgRi closed 2 years ago

YangHgRi commented 3 years ago

2021-11-03 10:40:33,268 - crypto_trading_logger - INFO - Starting Traceback (most recent call last): File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\urllib3\connectionpool.py", line 696, in urlopen self._prepare_proxy(conn) File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy conn.connect() File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\urllib3\connection.py", line 364, in connect conn = self._connect_tls_proxy(hostname, conn) File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\urllib3\connection.py", line 501, in _connect_tls_proxy socket = ssl_wrapsocket( File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\urllib3\util\ssl.py", line 449, in ssl_wrap_socket ssl_sock = _ssl_wrap_socketimpl( File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\urllib3\util\ssl.py", line 493, in _ssl_wrap_socket_impl return ssl_context.wrap_socket(sock, server_hostname=server_hostname) File "C:\Program Files\Python39\lib\ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "C:\Program Files\Python39\lib\ssl.py", line 1040, in _create self.do_handshake() File "C:\Program Files\Python39\lib\ssl.py", line 1309, in do_handshake self._sslobj.do_handshake() socket.timeout: _ssl.c:1112: The handshake operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\requests\adapters.py", line 439, in send resp = conn.urlopen( File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\urllib3\connectionpool.py", line 755, in urlopen retries = retries.increment( File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\urllib3\util\retry.py", line 574, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.binance.com', port=443): Max retries exceeded with url: /api/v3/ping (Caused by ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1112: The handshake operation timed out')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\19877\Desktop\binance-trade-bot\binance_trade_bot__main.py", line 5, in main() File "C:\Users\19877\Desktop\binance-trade-bot\binance_trade_bot\crypto_trading.py", line 18, in main manager = BinanceAPIManager(config, db, logger) File "C:\Users\19877\Desktop\binance-trade-bot\binance_trade_bot\binance_api_manager.py", line 20, in init self.binance_client = Client( File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\binance\client.py", line 300, in init__ self.ping() File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\binance\client.py", line 526, in ping return self._get('ping', version=self.PRIVATE_API_VERSION) File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\binance\client.py", line 371, in _get return self._request_api('get', path, signed, version, kwargs) File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\binance\client.py", line 334, in _request_api return self._request(method, uri, signed, kwargs) File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\binance\client.py", line 314, in _request self.response = getattr(self.session, method)(uri, kwargs) File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\requests\sessions.py", line 555, in get return self.request('GET', url, kwargs) File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\requests\sessions.py", line 542, in request resp = self.send(prep, send_kwargs) File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\requests\sessions.py", line 655, in send r = adapter.send(request, kwargs) File "C:\Users\19877\AppData\Roaming\Python\Python39\site-packages\requests\adapters.py", line 510, in send raise ProxyError(e, request=request) requests.exceptions.ProxyError: HTTPSConnectionPool(host='api.binance.com', port=443): Max retries exceeded with url: /api/v3/ping (Caused by ProxyError('Cannot connect to proxy.', timeout('_ssl.c:1112: The handshake operation timed out')))

zhangxiaoxing commented 2 years ago

Resolution: it is likely that you've set up your proxies like this...

proxies = {
  "http": "http://myproxy.org",
  "https": "https://myproxy.org",
}

Using this setup, you're trying to connect to the proxy using HTTP for HTTP requests, and using HTTPS for HTTPS requests.

But if you get the error above, it is likely that your proxy doesn't support connecting via HTTPS. Don't worry: that's a common gotcha.

Change the scheme of your HTTPS proxy to http://... instead of https://...:

proxies = {
  "http": "http://myproxy.org",
  "https": "http://myproxy.org",
}

This can be simplified to:

proxies = "http://myproxy.org"

For more information, see Proxies: FORWARD vs TUNNEL.