gpt4 book ai didi

python - 为什么请求会引发此异常 "check_hostname requires server_hostname"?

转载 作者:行者123 更新时间:2023-12-03 14:36:40 27 4
gpt4 key购买 nike

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:\Users\xyl13509876955\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\xyl13509876955\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\xyl13509876955\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\xyl13509876955\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\xyl13509876955\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "C:\Users\xyl13509876955\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "C:\Users\xyl13509876955\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "C:\Users\xyl13509876955\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "C:\Users\xyl13509876955\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py", line 359, in connect
conn = self._connect_tls_proxy(hostname, conn)
File "C:\Users\xyl13509876955\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py", line 506, in _connect_tls_proxy
ssl_context=ssl_context,
File "C:\Users\xyl13509876955\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\xyl13509876955\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\xyl13509876955\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 423, in wrap_socket
session=session
File "C:\Users\xyl13509876955\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
请帮助我解决问题,最好的方法是向我显示正确的代码。我对此感到非常困惑和沮丧!

最佳答案

据我了解,在新的urllib3中,代理的主要模式已更改...可以读取here
此设置对我有帮助(对于urllib3 = 1.26.4)。
旧的

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

关于python - 为什么请求会引发此异常 "check_hostname requires server_hostname"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66642705/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com