Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_all_currencies() causes SSL Error: WRONG_VERSION_NUMBER #129

Open
AnWeil opened this issue Dec 29, 2021 · 16 comments
Open

get_all_currencies() causes SSL Error: WRONG_VERSION_NUMBER #129

AnWeil opened this issue Dec 29, 2021 · 16 comments
Labels
bug Something isn't working

Comments

@AnWeil
Copy link

AnWeil commented Dec 29, 2021

I am running the script on a Raspberry Pi Zero 2 W with Raspbian Lite installed.
Everything is updated to the newest Version (Python Version: 3.9.2, did not try 3.10.x).
I configured everything and the bot ran fine for a while. Since a week or so i get the following output:

Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 382, in _make_request
    self._validate_conn(conn)
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
    conn.connect()
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connection.py", line 416, in connect
    self.sock = ssl_wrap_socket(
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/util/ssl_.py", line 449, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/util/ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.9/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.9/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/usr/lib/python3.9/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/gateio-crypto-trading-bot-binance-announcements-new-coins/src/main.py", line 47, in <module>
    supported_currencies = get_all_currencies(single=True)
  File "/home/pi/gateio-crypto-trading-bot-binance-announcements-new-coins/src/new_listings_scraper.py", line 173, in get_all_currencies
    all_currencies = ast.literal_eval(str(spot_api.list_currencies()))
  File "/home/pi/.local/lib/python3.9/site-packages/gate_api/api/spot_api.py", line 57, in list_currencies
    return self.list_currencies_with_http_info(**kwargs)  # noqa: E501
  File "/home/pi/.local/lib/python3.9/site-packages/gate_api/api/spot_api.py", line 111, in list_currencies_with_http_info
    return self.api_client.call_api(
  File "/home/pi/.local/lib/python3.9/site-packages/gate_api/api_client.py", line 395, in call_api
    return self.__call_api(
  File "/home/pi/.local/lib/python3.9/site-packages/gate_api/api_client.py", line 190, in __call_api
    response_data = self.request(
  File "/home/pi/.local/lib/python3.9/site-packages/gate_api/api_client.py", line 447, in request
    return self.rest_client.GET(
  File "/home/pi/.local/lib/python3.9/site-packages/gate_api/rest.py", line 237, in GET
    return self.request(
  File "/home/pi/.local/lib/python3.9/site-packages/gate_api/rest.py", line 218, in request
    r = self.pool_manager.request(
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/request.py", line 74, in request
    return self.request_encode_url(
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/request.py", line 96, in request_encode_url
    return self.urlopen(method, url, **extra_kw)
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/poolmanager.py", line 375, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 783, in urlopen
    return self.urlopen(
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 783, in urlopen
    return self.urlopen(
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 783, in urlopen
    return self.urlopen(
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/home/pi/.local/lib/python3.9/site-packages/urllib3/util/retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.gateio.ws', port=443): Max retries exceeded with url: /api/v4/spot/currencies (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)')))

I tried the following:
Saved the config files as well as the order.json and made a clean install on the raspberry pi with everything setup again but with no luck.
I also updated gate-api, openssl and requests to newest version without luck.

Best regards

@Linus045 Linus045 changed the title urllib3.exception get_all_currencies() causes SSL Error: WRONG_VERSION_NUMBER Jan 3, 2022
@Linus045 Linus045 added the bug Something isn't working label Jan 3, 2022
@hygren
Copy link

hygren commented Jan 3, 2022

Same issue here, on rpi4 raspbian lite

@hygren
Copy link

hygren commented Jan 3, 2022

Tried on Windows machine with python 3.9.9 and same error...

@nutbolt9
Copy link

nutbolt9 commented Jan 3, 2022

I get the same error. Given that the OP has mentioned it was working up to a week ago, I visited https://www.gate.io/docs/apiv4/en/#gate-api-v4-v4-22-2 and there you will see the access URL to the V4 API. (https://api.gateio.ws/api/v4) this is the link that is giving an SSL error, so looks like the error is at their end.

@hygren
Copy link

hygren commented Jan 3, 2022

How come it's working for lots of people then??

@AnWeil
Copy link
Author

AnWeil commented Jan 4, 2022

I tried three other installations now. Even on 3 different networks i always get the above error. I wanted to figure out if it may be a faulty router config.

@Linus045
Copy link
Collaborator

Linus045 commented Jan 4, 2022

I don't experience this problem, but could you try downgrading urllib3 as seen here:
https://stackoverflow.com/a/66656188

hygren mentioned it didn't work for him on the discord but I would like more people to try it to be sure.

@Linus045
Copy link
Collaborator

Linus045 commented Jan 4, 2022

Another idea I have is to provide a http address as the host for the gate_io bot:
The default host is https://api.gateio.ws/api/v4 which uses https, so maybe by forcing http it will work?

Replace in gateio_auth.py
return Configuration(key=auth["gateio_api"], secret=auth["gateio_secret"])
with
return Configuration(key=auth["gateio_api"], secret=auth["gateio_secret"], host="https://api.gateio.ws/api/v4")

I'm personally not really experienced with SSL and HTTPS so these are more or less just random ideas.

@AnWeil
Copy link
Author

AnWeil commented Jan 4, 2022

Ok i tried downgrading urllib3, but didn't change anything.

@AnWeil
Copy link
Author

AnWeil commented Jan 4, 2022

adding host to the return command didn't work.

@billg118
Copy link

billg118 commented Jan 4, 2022

What is the exact command you're running?

@AnWeil
Copy link
Author

AnWeil commented Jan 5, 2022

the exact command is: nohup python3 main.py &
to try the script i just run: python3 main.py so i can see the live output in the terminal

@Linus045
Copy link
Collaborator

Linus045 commented Jan 5, 2022

The easiest way to test if the error exists is to run this test script in a new test.py file:

from gate_api import ApiClient, Configuration, SpotApi

client = Configuration()
spot_api = SpotApi(ApiClient(client))
spot_api.list_currencies()

In my case the script just ends, but for some people it causes the same SSL Error.

@hygren
Copy link

hygren commented Jan 6, 2022

`pi@raspberrypi:~ $ cat testscript.py
from gate_api import ApiClient, Configuration, SpotApi

client = Configuration()
spot_api = SpotApi(ApiClient(client))
spot_api.list_currencies()
pi@raspberrypi:~ $ python testscript.py
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 597, in urlopen
httplib_response = self._make_request(conn, method, url,
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 343, in _make_request
self._validate_conn(conn)
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 849, in validate_conn
conn.connect()
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connection.py", line 349, in connect
self.sock = ssl_wrap_socket(
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/util/ssl
.py", line 359, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib/python3.9/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/usr/lib/python3.9/ssl.py", line 1040, in _create
self.do_handshake()
File "/usr/lib/python3.9/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/pi/testscript.py", line 5, in
spot_api.list_currencies()
File "/home/pi/.local/lib/python3.9/site-packages/gate_api/api/spot_api.py", line 57, in list_currencies
return self.list_currencies_with_http_info(**kwargs) # noqa: E501
File "/home/pi/.local/lib/python3.9/site-packages/gate_api/api/spot_api.py", line 111, in list_currencies_with_http_info
return self.api_client.call_api(
File "/home/pi/.local/lib/python3.9/site-packages/gate_api/api_client.py", line 395, in call_api
return self.__call_api(
File "/home/pi/.local/lib/python3.9/site-packages/gate_api/api_client.py", line 190, in __call_api
response_data = self.request(
File "/home/pi/.local/lib/python3.9/site-packages/gate_api/api_client.py", line 447, in request
return self.rest_client.GET(
File "/home/pi/.local/lib/python3.9/site-packages/gate_api/rest.py", line 237, in GET
return self.request(
File "/home/pi/.local/lib/python3.9/site-packages/gate_api/rest.py", line 218, in request
r = self.pool_manager.request(
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/request.py", line 66, in request
return self.request_encode_url(method, url, fields=fields,
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/request.py", line 89, in request_encode_url
return self.urlopen(method, url, **extra_kw)
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/poolmanager.py", line 322, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 663, in urlopen
return self.urlopen(method, url, body, headers, retries,
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 663, in urlopen
return self.urlopen(method, url, body, headers, retries,
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 663, in urlopen
return self.urlopen(method, url, body, headers, retries,
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 637, in urlopen
retries = retries.increment(method, url, error=e, _pool=self,
File "/home/pi/.local/lib/python3.9/site-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.gateio.ws', port=443): Max retries exceeded with url: /api/v4/spot/currencies (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)')))
pi@raspberrypi:~ $
`

@hygren
Copy link

hygren commented Jan 6, 2022

pi@raspberrypi:~ $ python --version
Python 3.9.2

@lcampanella98
Copy link

connecting to a VPN has resolved it for me. probably my wifi network has some weird proxy configured or something

@lynxul25
Copy link

The easiest way to test if the error exists is to run this test script in a new test.py file:

from gate_api import ApiClient, Configuration, SpotApi

client = Configuration()
spot_api = SpotApi(ApiClient(client))
spot_api.list_currencies()

In my case the script just ends, but for some people it causes the same SSL Error.

The script returns the same wrong_version_number error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants