python-binance connect "Client(public_key, private_key)" error

Hi,

client = Client(self.public_key, self.private_key)

I was able to confirm that an error occurs in this part, but I don’t know why. I am trading for a total of two accounts through a loop, and sometimes this error occurs. What could be the exact cause?

the total error log is

Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 700, in urlopen
httplib_response = self._make_request(
File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 383, in _make_request
self._validate_conn(conn)
File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 1017, in validate_conn
conn.connect()
File “/usr/lib/python3/dist-packages/urllib3/connection.py”, line 411, in connect
self.sock = ssl_wrap_socket(
File "/usr/lib/python3/dist-packages/urllib3/util/ssl
.py", line 449, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(
File "/usr/lib/python3/dist-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.10/ssl.py”, line 513, in wrap_socket
return self.sslsocket_class._create(
File “/usr/lib/python3.10/ssl.py”, line 1100, in _create
self.do_handshake()
File “/usr/lib/python3.10/ssl.py”, line 1371, in do_handshake
self._sslobj.do_handshake()
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/requests/adapters.py”, line 439, in send
resp = conn.urlopen(
File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 756, in urlopen
retries = retries.increment(
File “/usr/lib/python3/dist-packages/urllib3/util/retry.py”, line 532, in increment
raise six.reraise(type(error), error, _stacktrace)
File “/usr/lib/python3/dist-packages/six.py”, line 718, in reraise
raise value.with_traceback(tb)
File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 700, in urlopen
httplib_response = self._make_request(
File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 383, in _make_request
self._validate_conn(conn)
File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 1017, in validate_conn
conn.connect()
File “/usr/lib/python3/dist-packages/urllib3/connection.py”, line 411, in connect
self.sock = ssl_wrap_socket(
File "/usr/lib/python3/dist-packages/urllib3/util/ssl
.py", line 449, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(
File "/usr/lib/python3/dist-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.10/ssl.py”, line 513, in wrap_socket
return self.sslsocket_class._create(
File “/usr/lib/python3.10/ssl.py”, line 1100, in _create
self.do_handshake()
File “/usr/lib/python3.10/ssl.py”, line 1371, in do_handshake
self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: (‘Connection aborted.’, ConnectionResetError(104, ‘Connection reset by peer’))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/ubuntu/mmat/run/mmat.py”, line 186, in
mmat.run()
File “/home/ubuntu/mmat/run/mmat.py”, line 169, in run
self.get_users()
File “/home/ubuntu/mmat/run/mmat.py”, line 70, in get_users
user = User(
File “/home/ubuntu/mmat/run/user.py”, line 30, in init
self.client = self.get_client()
File “/home/ubuntu/mmat/run/user.py”, line 69, in get_client
client = Client(self.public_key, self.private_key)
File “/usr/local/lib/python3.10/dist-packages/binance/client.py”, line 344, in init
self.ping()
File “/usr/local/lib/python3.10/dist-packages/binance/client.py”, line 570, in ping
return self._get(‘ping’, version=self.PRIVATE_API_VERSION)
File “/usr/local/lib/python3.10/dist-packages/binance/client.py”, line 415, in _get
return self._request_api(‘get’, path, signed, version, **kwargs)
File “/usr/local/lib/python3.10/dist-packages/binance/client.py”, line 378, in _request_api
return self._request(method, uri, signed, **kwargs)
File “/usr/local/lib/python3.10/dist-packages/binance/client.py”, line 358, in _request
self.response = getattr(self.session, method)(uri, **kwargs)
File “/usr/lib/python3/dist-packages/requests/sessions.py”, line 557, in get
return self.request(‘GET’, url, **kwargs)
File “/usr/lib/python3/dist-packages/requests/sessions.py”, line 544, in request
resp = self.send(prep, **send_kwargs)
File “/usr/lib/python3/dist-packages/requests/sessions.py”, line 657, in send
r = adapter.send(request, **kwargs)
File “/usr/lib/python3/dist-packages/requests/adapters.py”, line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: (‘Connection aborted.’, ConnectionResetError(104, ‘Connection reset by peer’))

please help me… thank you

The reason for this connection issue could be variable. Please try to reconnect, it should work.

I`m not using websocket… only use rest api.
How can i implement to reconnect client ??
Are you just telling me to run the same code again that connects through exception handling?