sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.11k stars 2.22k forks source link

ValueError: check_hostname requires server_hostname #734

Open vicktw opened 3 years ago

vicktw commented 3 years ago

Describe the bug I use PyCharm + Ananconda , when i put the following codes with my own Binance API key and API secret . it pops up errors.

To Reproduce from binance.client import Client api_key = "X0*DK" api_secret = "8E**eD" client = Client(api_key, api_secret)

Expected behavior Just want someone can tell me how to fix this problem

Environment (please complete the following information):

Logs or Additional context None

AlexNik commented 3 years ago

@vicktw Which error?

vicktw commented 3 years ago

@vicktw Which error?

Traceback (most recent call last): File "D:\MyPython\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3437, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in runfile('C:/Users/yu/Desktop/PythonFiles/PyCharm/MyProject/test1.py', wdir='C:/Users/yu/Desktop/PythonFiles/PyCharm/MyProject') File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev_pydev_bundle\pydev_umd.py", line 197, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/yu/Desktop/PythonFiles/PyCharm/MyProject/test1.py", line 5, in client = Client(api_key, api_secret) File "C:\Users\yu\Desktop\PythonFiles\PyCharm\MyProject\venv\lib\site-packages\binance\client.py", line 105, in init self.ping() File "C:\Users\yu\Desktop\PythonFiles\PyCharm\MyProject\venv\lib\site-packages\binance\client.py", line 392, in ping return self._get('ping', version=self.PRIVATE_API_VERSION) File "C:\Users\yu\Desktop\PythonFiles\PyCharm\MyProject\venv\lib\site-packages\binance\client.py", line 237, in _get return self._request_api('get', path, signed, version, kwargs) File "C:\Users\yu\Desktop\PythonFiles\PyCharm\MyProject\venv\lib\site-packages\binance\client.py", line 202, in _request_api return self._request(method, uri, signed, kwargs) File "C:\Users\yu\Desktop\PythonFiles\PyCharm\MyProject\venv\lib\site-packages\binance\client.py", line 196, in _request self.response = getattr(self.session, method)(uri, kwargs) File "D:\MyPython\Anaconda3\lib\site-packages\requests\sessions.py", line 555, in get return self.request('GET', url, kwargs) File "D:\MyPython\Anaconda3\lib\site-packages\requests\sessions.py", line 542, in request resp = self.send(prep, send_kwargs) File "D:\MyPython\Anaconda3\lib\site-packages\requests\sessions.py", line 655, in send r = adapter.send(request, kwargs) File "D:\MyPython\Anaconda3\lib\site-packages\requests\adapters.py", line 439, in send resp = conn.urlopen( File "D:\MyPython\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen self._prepare_proxy(conn) File "D:\MyPython\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy conn.connect() File "D:\MyPython\Anaconda3\lib\site-packages\urllib3\connection.py", line 359, in connect conn = self._connect_tls_proxy(hostname, conn) File "D:\MyPython\Anaconda3\lib\site-packages\urllib3\connection.py", line 500, in _connect_tls_proxy return ssl_wrapsocket( File "D:\MyPython\Anaconda3\lib\site-packages\urllib3\util\ssl.py", line 432, in ssl_wrap_socket ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_intls) File "D:\MyPython\Anaconda3\lib\site-packages\urllib3\util\ssl.py", line 474, in _ssl_wrap_socket_impl return ssl_context.wrap_socket(sock) File "D:\MyPython\Anaconda3\lib\ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "D:\MyPython\Anaconda3\lib\ssl.py", line 997, in _create raise ValueError("check_hostname requires server_hostname") ValueError: check_hostname requires server_hostname

Bob12345 commented 3 years ago

ValueError: check_hostname requires server_hostname. Can you run it through a Visual Studio or another IDE and see how the hostname is resolved?

vicktw commented 3 years ago

ValueError: check_hostname requires server_hostname. Can you run it through a Visual Studio or another IDE and see how the hostname is resolved?

Hi Bob , Thank you for helping , i run it on IDLE shell 3.9.1 , it pop up another errors:

====== RESTART: C:\Users\yu\Desktop\PythonFiles\PyCharm\MyProject\test1.py ===== Traceback (most recent call last): File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen self._prepare_proxy(conn) File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy conn.connect() File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 359, in connect conn = self._connect_tls_proxy(hostname, conn) File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 496, in _connect_tls_proxy return ssl_wrapsocket( File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\ssl.py", line 432, in ssl_wrap_socket ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_intls) File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\ssl.py", line 474, in _ssl_wrap_socket_impl return ssl_context.wrap_socket(sock) File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1040, in _create self.do_handshake() File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\ssl.py", line 1309, in do_handshake self._sslobj.do_handshake() socket.timeout: _ssl.c:1106: The handshake operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 439, in send resp = conn.urlopen( File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen retries = retries.increment( File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\retry.py", line 573, 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:1106: The handshake operation timed out')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\yu\Desktop\PythonFiles\PyCharm\MyProject\test1.py", line 8, in client = Client(api_key, api_secret) File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\binance\client.py", line 105, in init self.ping() File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\binance\client.py", line 392, in ping return self._get('ping', version=self.PRIVATE_API_VERSION) File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\binance\client.py", line 237, in _get return self._request_api('get', path, signed, version, kwargs) File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\binance\client.py", line 202, in _request_api return self._request(method, uri, signed, kwargs) File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\binance\client.py", line 196, in _request self.response = getattr(self.session, method)(uri, kwargs) File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 555, in get return self.request('GET', url, kwargs) File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 542, in request resp = self.send(prep, send_kwargs) File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 655, in send r = adapter.send(request, kwargs) File "C:\Users\yu\AppData\Local\Programs\Python\Python39\lib\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:1106: The handshake operation timed out')))

AlexNik commented 3 years ago

@vicktw do you use proxy? Could you ping https://api.binance.com? Or open in browser this site https://api.binance.com/api/v3/ping There must be the following page:

{} 
Bob12345 commented 3 years ago

Looks like you're being blocked somehow. Use curl or ping to see that you're not blocked by either Binance or your own network/firefall. Or do what Alex, just saw it :D

vicktw commented 3 years ago

@vicktw do you use proxy? Could you ping https://api.binance.com? Or open in browser this site https://api.binance.com/api/v3/ping There must be the following page:

{} 

Looks like you're being blocked somehow. Use curl or ping to see that you're not blocked by either Binance or your own network/firefall. Or do what Alex, just saw it :D

Oh , yes my internet is blocked ..... Thank you so much Bob and Alex .