网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

PythonRequests:proxy代理错误-创新互联

目标:www.baidu.com

站在用户的角度思考问题,与客户深入沟通,找到衡阳县网站设计与衡阳县网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站制作、成都网站制作、企业官网、英文网站、手机端网站、网站推广、域名与空间、网站空间、企业邮箱。业务覆盖衡阳县地区。

源码:

import requests url = 'http://www.baidu.com' header = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'     } free_proxy = { #都是http类型地址 ##'http': '163.204.241.160:9999' 'http': '123.206.54.52:8118'     } response = requests.get(url=url, headers=header, proxies=free_proxy) print(response.status_code)

使用代理'163.204.241.160:9999'出现

ProxyError

Traceback (most recent call last):   File "D:\Software\python3.7.4\lib\site-packages\urllib3\connection.py", line 160, in _new_conn     (self._dns_host, self.port), self.timeout, **extra_kw)   File "D:\Software\python3.7.4\lib\site-packages\urllib3\util\connection.py", line 80, in create_connection     raise err   File "D:\Software\python3.7.4\lib\site-packages\urllib3\util\connection.py", line 70, 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:\Software\python3.7.4\lib\site-packages\urllib3\connectionpool.py", line 603, in urlopen     chunked=chunked)   File "D:\Software\python3.7.4\lib\site-packages\urllib3\connectionpool.py", line 355, in _make_request     conn.request(method, url, **httplib_request_kw)   File "D:\Software\python3.7.4\lib\http\client.py", line 1244, in request     self._send_request(method, url, body, headers, encode_chunked)   File "D:\Software\python3.7.4\lib\http\client.py", line 1290, in _send_request     self.endheaders(body, encode_chunked=encode_chunked)   File "D:\Software\python3.7.4\lib\http\client.py", line 1239, in endheaders     self._send_output(message_body, encode_chunked=encode_chunked)   File "D:\Software\python3.7.4\lib\http\client.py", line 1026, in _send_output     self.send(msg)   File "D:\Software\python3.7.4\lib\http\client.py", line 966, in send     self.connect()   File "D:\Software\python3.7.4\lib\site-packages\urllib3\connection.py", line 183, in connect     conn = self._new_conn()   File "D:\Software\python3.7.4\lib\site-packages\urllib3\connection.py", line 169, in _new_conn     self, "Failed to establish a new connection: %s" % e) urllib3.exceptions.NewConnectionError: : Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。 During handling of the above exception, another exception occurred: Traceback (most recent call last):   File "D:\Software\python3.7.4\lib\site-packages\requests\adapters.py", line 449, in send     timeout=timeout   File "D:\Software\python3.7.4\lib\site-packages\urllib3\connectionpool.py", line 641, in urlopen     _stacktrace=sys.exc_info()[2])   File "D:\Software\python3.7.4\lib\site-packages\urllib3\util\retry.py", line 399, in increment     raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='182.34.33.38', port=9999): Max retries exceeded with url: http://www.baidu.com/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))) During handling of the above exception, another exception occurred: Traceback (most recent call last):   File "D:/Study/工作/待解决问题/requests/requests_proxy.py", line 15, in      response = requests.get(url=url, headers=header, proxies=free_proxy)   File "D:\Software\python3.7.4\lib\site-packages\requests\api.py", line 75, in get     return request('get', url, params=params, **kwargs)   File "D:\Software\python3.7.4\lib\site-packages\requests\api.py", line 60, in request     return session.request(method=method, url=url, **kwargs)   File "D:\Software\python3.7.4\lib\site-packages\requests\sessions.py", line 533, in request     resp = self.send(prep, **send_kwargs)   File "D:\Software\python3.7.4\lib\site-packages\requests\sessions.py", line 646, in send     r = adapter.send(request, **kwargs)   File "D:\Software\python3.7.4\lib\site-packages\requests\adapters.py", line 510, in send     raise ProxyError(e, request=request) requests.exceptions.ProxyError: HTTPConnectionPool(host='182.34.33.38', port=9999): Max retries exceeded with url: http://www.baidu.com/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))

查过自己电脑网络配置中没有设置代理。

使用代理'123.206.54.52:8118'出现

ChunkedEncodingError

Traceback (most recent call last):   File "D:\Software\python3.7.4\lib\site-packages\urllib3\response.py", line 397, in _error_catcher     yield   File "D:\Software\python3.7.4\lib\site-packages\urllib3\response.py", line 479, in read     data = self._fp.read(amt)   File "D:\Software\python3.7.4\lib\http\client.py", line 457, in read     n = self.readinto(b)   File "D:\Software\python3.7.4\lib\http\client.py", line 501, in readinto     n = self.fp.readinto(b)   File "D:\Software\python3.7.4\lib\socket.py", line 589, 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 "D:\Software\python3.7.4\lib\site-packages\requests\models.py", line 750, in generate     for chunk in self.raw.stream(chunk_size, decode_content=True):   File "D:\Software\python3.7.4\lib\site-packages\urllib3\response.py", line 531, in stream     data = self.read(amt=amt, decode_content=decode_content)   File "D:\Software\python3.7.4\lib\site-packages\urllib3\response.py", line 496, in read     raise IncompleteRead(self._fp_bytes_read, self.length_remaining)   File "D:\Software\python3.7.4\lib\contextlib.py", line 130, in __exit__     self.gen.throw(type, value, traceback)   File "D:\Software\python3.7.4\lib\site-packages\urllib3\response.py", line 415, in _error_catcher     raise ProtocolError('Connection broken: %r' % e, e) urllib3.exceptions.ProtocolError: ("Connection broken: ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None)", ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None)) During handling of the above exception, another exception occurred: Traceback (most recent call last):   File "D:/Study/工作/待解决问题/requests/requests_proxy.py", line 16, in      response = requests.get(url=url, headers=header, proxies=free_proxy)   File "D:\Software\python3.7.4\lib\site-packages\requests\api.py", line 75, in get     return request('get', url, params=params, **kwargs)   File "D:\Software\python3.7.4\lib\site-packages\requests\api.py", line 60, in request     return session.request(method=method, url=url, **kwargs)   File "D:\Software\python3.7.4\lib\site-packages\requests\sessions.py", line 533, in request     resp = self.send(prep, **send_kwargs)   File "D:\Software\python3.7.4\lib\site-packages\requests\sessions.py", line 686, in send     r.content   File "D:\Software\python3.7.4\lib\site-packages\requests\models.py", line 828, in content     self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''   File "D:\Software\python3.7.4\lib\site-packages\requests\models.py", line 753, in generate     raise ChunkedEncodingError(e) requests.exceptions.ChunkedEncodingError: ("Connection broken: ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None)", ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None))

推荐阅读:https://blog.csdn.net/wangzuxi/article/details/40377467  

最后,将url = 'http://www.baidu.com' 改成 url = 'https://www.baidu.com', 使用以上两个代理地址测试都能成功,结果:200

-----

换了一个新的代理: 'http': '47.93.36.195:8118' 

url = 'http://www.baidu.com' 

多次运行,返回状态有200,503,还有ChunkedEncodingError

由此可见,ChunkedEncodingError错误并不是代理问题,为稳定,还是将url改为https为好。

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页名称:PythonRequests:proxy代理错误-创新互联
网站路径:http://bjjierui.cn/article/gjjdg.html

其他资讯