gpt4 book ai didi

Python请求: using proxy but get connect 'Connection aborted'

转载 作者:太空宇宙 更新时间:2023-11-03 19:45:45 25 4
gpt4 key购买 nike

  1. 我的 VPN 运行良好,可以访问 google(从中国)。
  2. 我的 VPN 的 sock5 端口:1080
  3. 但是当我运行以下代码时,出现错误。
import requests
headers = {'user-agent': ''}
proxies = {"http": "socks5://127.0.0.1:1080",'https': 'socks5://127.0.0.1:1080'}

# url = 'https://www.baidu.com/'
url = 'https://www.google.com/search?q=python' #
res = requests.get(url, headers=headers, proxies=proxies)
print("res.status_code:\n",res.status_code)
  • 如果我删除 , proxies=proxies 并将 url 更改为 baidu 就可以了。
  • ...
    url = 'https://www.baidu.com/'
    # url = 'https://www.google.com/search?q=python'
    res = requests.get(url, headers=headers)
    print("res.status_code:\n",res.status_code)
  • 3中的错误:
  • Traceback (most recent call last):
    File "Try.py", line 17, in <module>
    res = requests.get(url, headers=headers, proxies=proxies)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests-2.22.0-py3.7.egg/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests-2.22.0-py3.7.egg/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests-2.22.0-py3.7.egg/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests-2.22.0-py3.7.egg/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests-2.22.0-py3.7.egg/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
    requests.exceptions.ConnectionError: ('Connection aborted.', OSError(0, 'Error'))

    从1到4,1和4矛盾,我实在不知道问题出在哪里。如果有人可以提供帮助,我将非常感激。

    最佳答案

    通过用 sock5h 替换 sock5 解决

    关于Python请求: using proxy but get connect 'Connection aborted' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60153818/

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