Python爬虫的一个问题(困扰了很长时间了)

DeEP霜降 发布于 2017/12/20 12:30
阅读 8K+
收藏 1

C:\Users\Administrator>python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.


>>> import requests
>>> response = requests.get('https://www.baidu.com')

Traceback (most recent call last):
  File "D:\Anaconda\install\lib\site-packages\urllib3\connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "D:\Anaconda\install\lib\site-packages\urllib3\util\connection.py", line 83, in create_connection
    raise err
  File "D:\Anaconda\install\lib\site-packages\urllib3\util\connection.py", line 73, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Anaconda\install\lib\site-packages\urllib3\connectionpool.py", line 595, in urlopen
    self._prepare_proxy(conn)
  File "D:\Anaconda\install\lib\site-packages\urllib3\connectionpool.py", line 816, in _prepare_proxy
    conn.connect()
  File "D:\Anaconda\install\lib\site-packages\urllib3\connection.py", line 284, in connect
    conn = self._new_conn()
  File "D:\Anaconda\install\lib\site-packages\urllib3\connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x000002F48FB77400>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Anaconda\install\lib\site-packages\requests\adapters.py", line 440, in send
    timeout=timeout
  File "D:\Anaconda\install\lib\site-packages\urllib3\connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "D:\Anaconda\install\lib\site-packages\urllib3\util\retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000002F48FB77400>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。',)))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Anaconda\install\lib\site-packages\requests\api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "D:\Anaconda\install\lib\site-packages\requests\api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\Anaconda\install\lib\site-packages\requests\sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\Anaconda\install\lib\site-packages\requests\sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "D:\Anaconda\install\lib\site-packages\requests\adapters.py", line 502, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000002F48FB77400>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。',)))
>>>

百度了很长时间也没有解决,网上很少有这些问题,希望有大神帮助解决 

 

加载中
0
mummy
mummy

软件问题?

0
yuzhouliu
yuzhouliu

实测毫无问题

0
南寻
南寻
加个请求头试试
0
大洋的顶端
大洋的顶端

http://www.baidu.com 取消HTTPS

大洋的顶端
大洋的顶端
回复 @DeEP霜降 : 换个网站看看行不行
DeEP霜降
DeEP霜降
还是没用
0
wei2011
wei2011

实测没问题。试一下浏览器能访问 https://www.baidu.com么,换个别的地址试试

0
j
jackme

过于频繁的爬取,被目标识别为机器临时或永久屏蔽

0
j
jackme

没有使用header头部模拟浏览器进行伪装,直接使用get,被baidu封杀在所难免。百度爬取整个互联网,是爬虫老大,明显弄斧到班门。

0
polly
polly
积极拒绝,就是发现你的连接不寻常,不接受请求。看看是否被封了ip,如果没有加ua模拟浏览器
0
剑心无痕
剑心无痕

response = requests.get('https://www.baidu.com', proxies={'https':'https://175.171.110.49:53281'})

走代理,你的ip被暂时封了

返回顶部
顶部