Skip to content
Advertisement

Why requests raise this exception “check_hostname requires server_hostname”?

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)

And then it raise the exception:

Traceback (most recent call last):
  File "C:Usersxyl13509876955DesktopMonitordicks.py", line 61, in send_request
    self.response=requests.get(url=url,headers=self.headers,timeout=(6,15),proxies=p)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packagesrequestsapi.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packagesrequestsapi.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packagesrequestssessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packagesrequestssessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packagesrequestsadapters.py", line 449, in send
    timeout=timeout
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packagesurllib3connectionpool.py", line 696, in urlopen
    self._prepare_proxy(conn)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packagesurllib3connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packagesurllib3connection.py", line 359, in connect
    conn = self._connect_tls_proxy(hostname, conn)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packagesurllib3connection.py", line 506, in _connect_tls_proxy
    ssl_context=ssl_context,
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packagesurllib3utilssl_.py", line 432, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packagesurllib3utilssl_.py", line 474, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libssl.py", line 423, in wrap_socket
    session=session
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libssl.py", line 827, in _create
    raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname

Please help me solve the problem and the best way is to show me the right code. I am very confused and frustrated for the problem!!

Advertisement

Answer

As I understand, in new urllib3 the main schema of proxy was changed… can read here. 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',
    } 

UPDATED

I have met this issue again for requests 2.26.0, but in this time it works with an old schema…

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

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement