为什么请求会引发此异常“check_hostname 需要 server_hostname"? [英] Why requests raise this exception "check_hostname requires server_hostname"?

查看:32
本文介绍了为什么请求会引发此异常“check_hostname 需要 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)

然后它引发异常:

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-packages
equestsapi.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packages
equestsapi.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packages
equestssessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packages
equestssessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "C:Usersxyl13509876955AppDataLocalProgramsPythonPython37libsite-packages
equestsadapters.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!!

推荐答案

据我所知,在新的 urllib3 中,代理的主要架构发生了变化...可以阅读 此处.这个设置对我有帮助(对于 urllib3=1.26.4).

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).

老了

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

新的

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


更新

我在 requests 2.26.0 中再次遇到了这个问题,但这次它适用于旧架构......

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'
    }

这篇关于为什么请求会引发此异常“check_hostname 需要 server_hostname"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆