m0_46313767 2020-09-04 19:23 采纳率: 0%
浏览 421

爬虫 ProxyError 急!!!

爬虫新手,在使用requests.get()中proxies参数后仍旧报错

这不是最困惑的,最困惑的是同样的代码**在服务器上可以成功使用代理,然而我的电脑就无法使用代理,一旦使用就报错**
**之前我也使用过迅云vpn,不知道和这个有无关系

#更换ip函数
def get_proxies(web):
    while True:
        try:
            r = requests.get(web).text
        except Exception as e:
            print("ip更换过快")
            time.sleep(random.random()*3+3)
            continue
        print(json.loads(r))
        ip = json.loads(r)["data"][0]["ip"]
        port = json.loads(r)["data"][0]["port"]
        proxy = ip + ':' + str(port)
        proxies = {'http':'http://'+proxy,'https':'https://'+proxy}
        print(proxies)
        try:
            test = requests.get("https://httpbin.org/get",proxies = proxies,timeout=10).text
            print(test)
        except Exception as e:
            print('ip不可用')
            time.sleep(random.random() * 3 + 5)
            continue
        test = json.loads(test)
        print('ip为:',test["origin"])
        break
    return proxies

函数本身没有问题
报错:

Traceback (most recent call last):

  File "G:\anaconda\lib\site-packages\urllib3\connectionpool.py", line 667, in urlopen
    self._prepare_proxy(conn)

  File "G:\anaconda\lib\site-packages\urllib3\connectionpool.py", line 930, in _prepare_proxy
    conn.connect()

  File "G:\anaconda\lib\site-packages\urllib3\connection.py", line 316, in connect
    self._tunnel()

  File "G:\anaconda\lib\http\client.py", line 896, in _tunnel
    (version, code, message) = response._read_status()

  File "G:\anaconda\lib\http\client.py", line 264, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")

  File "G:\anaconda\lib\socket.py", line 669, in readinto
    return self._sock.recv_into(b)

ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "G:\anaconda\lib\site-packages\requests\adapters.py", line 439, in send
    resp = conn.urlopen(

  File "G:\anaconda\lib\site-packages\urllib3\connectionpool.py", line 724, in urlopen
    retries = retries.increment(

  File "G:\anaconda\lib\site-packages\urllib3\util\retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))

MaxRetryError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /get (Caused by ProxyError('Cannot connect to proxy.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None)))


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "C:\Users\lenovo\Desktop\7500-10000\7500-10000.py", line 80, in get_proxies
    test = requests.get("https://httpbin.org/get",proxies = proxies,timeout=10).text

  File "G:\anaconda\lib\site-packages\requests\api.py", line 76, in get
    return request('get', url, params=params, **kwargs)

  File "G:\anaconda\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)

  File "G:\anaconda\lib\site-packages\requests\sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)

  File "G:\anaconda\lib\site-packages\requests\sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)

  File "G:\anaconda\lib\site-packages\requests\adapters.py", line 510, in send
    raise ProxyError(e, request=request)

ProxyError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /get (Caused by ProxyError('Cannot connect to proxy.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None)))
  • 写回答

1条回答 默认 最新

  • threenewbee 2020-09-04 22:15
    关注

    在你的电脑的 internet 选项,连接,代理服务器中设置下这个代理ip,端口,通过浏览器访问,看看是否可以访问。
    应该是某种机制阻断了代理服务器和你计算机的连接。

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?