Skip to content
Home » ValueError: check_hostname requires server_hostname

ValueError: check_hostname requires server_hostname

To solve ValueError: check_hostname requires server_hostname error follow below methods. When using the pip command to install or uninstall a Python package, you may see the error message ValueError: check hostname requires server hostname, as seen below. This post will show you how to repair it.

ERROR LOG

p={
    'http':'http://my correct proxy here',
    'https':'https://my correct proxy here'
    }
self.response=requests.get(url=url,headers=self.headers,timeout=(6,15),proxies=p)

While running the similar code to above, caught with below error.

Traceback (most recent call last):
  File "C:\Users\x\Desktop\Monitor\dicks.py", line 61, in send_request
    self.response=requests.get(url=url,headers=self.headers,timeout=(6,15),proxies=p)
  File "C:\Users\x\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py", line 506, in _connect_tls_proxy
    ssl_context=ssl_context,
  File "C:\Users\x\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\ssl_.py", line 432, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
  File "C:\Users\x\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\ssl_.py", line 474, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock)
  File "C:\Users\x\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 423, in wrap_socket
    session=session
  File "C:\Users\x\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 827, in _create
    raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname

Why ValueError: check_hostname requires server_hostname occurs ?

This issue occurs because you are connecting to the internet using a proxy server (for example, SSR or v2ray).
Simply close and exit the proxy server that you are using to resolve the problem. The python package can then be successfully managed with the pip command.

How to solve ValueError: check_hostname requires server_hostname ?

Working well in urllib3 version 1.25.11. So, use the following command line to install urllib3 1.25.11.

pip install urllib3==1.25.11

Alternative to Solve ValueError: check_hostname requires server_hostname

Actually, the main schema of the proxy, urllib3, was modified, and if you are using urllib3=1.26.4, then use the code below. Simply run this command to downgrade the urllib3 version. You may install urllib3==1.25.8 with pip.

This settings help for me (for urllib3=1.26.4).

An old

proxy={
    'http':'8.88.888.8:8888',
    'https':'8.88.888.8:8888'
    }

The new

proxy={
    'https': 'https://8.88.888.8:8888',
    'http': 'http://8.88.888.8:8888',
    } 

Hope the above solution works.

Also read :

ERROR:gpu_init.cc(426) Passthrough is not supported GL is disabled
Command ‘python.execInTerminal-icon’ not found in Visual Studio Code