bybit-exchange / pybit

Official Python3 API connector for Bybit's HTTP and WebSockets APIs.
Other
340 stars 113 forks source link

ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number #217

Closed Leggerla closed 3 days ago

Leggerla commented 1 month ago

When executing this code

from pybit.unified_trading import HTTP

session = HTTP(
    testnet=False,
    api_key=api_key,
    api_secret=api_secret,
)

response = session.place_order(
    category="spot",
    symbol="MONUSDT",
    side="Buy",
    orderType="Market",
    qty="0.1",
    timeInForce="GTC",
)

I get this error

Traceback (most recent call last): File "C:\Users\Lucy\Side projects\ListingAPI\venv\lib\site-packages\urllib3\connectionpool.py", line 467, in _make_request self._validate_conn(conn) File "C:\Users\Lucy\Side projects\ListingAPI\venv\lib\site-packages\urllib3\connectionpool.py", line 1099, in _validate_conn conn.connect() File "C:\Users\Lucy\Side projects\ListingAPI\venv\lib\site-packages\urllib3\connection.py", line 653, in connect sock_and_verified = _ssl_wrap_socket_and_match_hostname( File "C:\Users\Lucy\Side projects\ListingAPI\venv\lib\site-packages\urllib3\connection.py", line 806, in _ssl_wrap_socket_and_match_hostname ssl_sock = ssl_wrapsocket( File "C:\Users\Lucy\Side projects\ListingAPI\venv\lib\site-packages\urllib3\util\ssl.py", line 465, in ssl_wrap_socket ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, serverhostname) File "C:\Users\Lucy\Side projects\ListingAPI\venv\lib\site-packages\urllib3\util\ssl.py", line 509, in _ssl_wrap_socket_impl return ssl_context.wrap_socket(sock, server_hostname=server_hostname) File "C:\Users\Lucy\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 513, in wrap_socket return self.sslsocket_class._create( File "C:\Users\Lucy\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1071, in _create self.do_handshake() File "C:\Users\Lucy\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1342, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)

Python version: 3.10, OS: Windows 11, IDE: PyCharm Package versions: certifi 2024.2.2 charset-normalizer 3.3.2 idna 3.7 packaging 24.0 pip 24.0 pybit 5.7.0 pycryptodome 3.19.0 python-certifi-win32 1.5 requests 2.32.2 setuptools 70.0.0 setuptools-scm 8.1.0 tomli 2.0.1 urllib3 2.2.1 websocket-client 1.5.0 websockets 12.0 wrapt 1.16.0

dextertd commented 3 days ago

I don't think this is a pybit issue, it's a problem with the SSL configuration or certificate on certain machines. It seems to mainly happen on Windows machines, but it's not consistent and cannot be address with an update to pybit. This should be investigated separately and I would expect it to impact anything using SSL.