Open lingdaiqishi opened 9 months ago
这应该是你的代理工具没开全局
运行以下代码测试:
import httpx
url = 'https://www.youtube.com/'
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
'referer': 'https://www.youtube.com/'
}
response = httpx.get(url, headers=headers)
print(response.text)
print(f'status_code : {response.status_code}')
如果你知道代理端口,可以配置settings文件中的proxy解决
详情参见 #11
还真是没开全局,hhh,太感谢大佬了(开了全局后又试了好久还是连不上,发现全局模式节点自动切回了直连= =)
两个t都能正常浏览网页,但是都连接失败...... `D:\runtime\Python\python.exe E:\Downloads\twitter_download-main\main.py 获取信息失败 Traceback (most recent call last): File "D:\runtime\Python\lib\site-packages\httpcore_exceptions.py", line 10, in map_exceptions yield File "D:\runtime\Python\lib\site-packages\httpcore_backends\sync.py", line 168, in start_tls raise exc File "D:\runtime\Python\lib\site-packages\httpcore_backends\sync.py", line 163, in start_tls sock = ssl_context.wrap_socket( File "D:\runtime\Python\lib\ssl.py", line 500, in wrap_socket return self.sslsocket_class._create( File "D:\runtime\Python\lib\ssl.py", line 1040, in _create self.do_handshake() File "D:\runtime\Python\lib\ssl.py", line 1309, in do_handshake self._sslobj.do_handshake() OSError: [Errno 0] Error
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "D:\runtime\Python\lib\site-packages\httpx_transports\default.py", line 66, in map_httpcore_exceptions yield File "D:\runtime\Python\lib\site-packages\httpx_transports\default.py", line 228, in handle_request resp = self._pool.handle_request(req) File "D:\runtime\Python\lib\site-packages\httpcore_sync\connection_pool.py", line 268, in handle_request raise exc File "D:\runtime\Python\lib\site-packages\httpcore_sync\connection_pool.py", line 251, in handle_request response = connection.handle_request(request) File "D:\runtime\Python\lib\site-packages\httpcore_sync\http_proxy.py", line 289, in handle_request connect_response = self._connection.handle_request( File "D:\runtime\Python\lib\site-packages\httpcore_sync\connection.py", line 99, in handle_request raise exc File "D:\runtime\Python\lib\site-packages\httpcore_sync\connection.py", line 76, in handle_request stream = self._connect(request) File "D:\runtime\Python\lib\site-packages\httpcore_sync\connection.py", line 156, in _connect stream = stream.start_tls(**kwargs) File "D:\runtime\Python\lib\site-packages\httpcore_backends\sync.py", line 168, in start_tls raise exc File "D:\runtime\Python\lib\contextlib.py", line 131, in exit self.gen.throw(type, value, traceback) File "D:\runtime\Python\lib\site-packages\httpcore_exceptions.py", line 14, in map_exceptions raise to_exc(exc) from exc httpcore.ConnectError: [Errno 0] Error
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "E:\Downloads\twitter_download-main\main.py", line 84, in get_other_info response = httpx.get(url, headers=_headers, proxies=proxies).text File "D:\runtime\Python\lib\site-packages\httpx_api.py", line 189, in get return request( File "D:\runtime\Python\lib\site-packages\httpx_api.py", line 100, in request return client.request( File "D:\runtime\Python\lib\site-packages\httpx_client.py", line 814, in request return self.send(request, auth=auth, follow_redirects=follow_redirects) File "D:\runtime\Python\lib\site-packages\httpx_client.py", line 901, in send response = self._send_handling_auth( File "D:\runtime\Python\lib\site-packages\httpx_client.py", line 929, in _send_handling_auth response = self._send_handling_redirects( File "D:\runtime\Python\lib\site-packages\httpx_client.py", line 966, in _send_handling_redirects response = self._send_single_request(request) File "D:\runtime\Python\lib\site-packages\httpx_client.py", line 1002, in _send_single_request response = transport.handle_request(request) File "D:\runtime\Python\lib\site-packages\httpx_transports\default.py", line 228, in handle_request resp = self._pool.handle_request(req) File "D:\runtime\Python\lib\contextlib.py", line 131, in exit self.gen.throw(type, value, traceback) File "D:\runtime\Python\lib\site-packages\httpx_transports\default.py", line 83, in map_httpcore_exceptions raise mapped_exc(message) from exc httpx.ConnectError: [Errno 0] Error
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "E:\Downloads\twitter_download-main\main.py", line 287, in
main(User_info(i))
File "E:\Downloads\twitter_download-main\main.py", line 266, in main
if not get_other_info(_user_info):
File "E:\Downloads\twitter_download-main\main.py", line 93, in get_other_info
print(response)
UnboundLocalError: local variable 'response' referenced before assignment
Process finished with exit code 1 `