Python:[WinError 10061] 由于目标计算机积极拒绝,无法连接。

这篇具有很好参考价值的文章主要介绍了Python:[WinError 10061] 由于目标计算机积极拒绝,无法连接。。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

错误描述

进行Python爬虫时出现报错:[WinError 10061] 由于目标计算机积极拒绝,无法连接。

Traceback (most recent call last):
  File "C:\Users\pc\AppData\Roaming\Python\Python39\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "C:\Users\pc\AppData\Roaming\Python\Python39\site-packages\urllib3\util\connection.py", line 95, in create_connection
    raise err
  File "C:\Users\pc\AppData\Roaming\Python\Python39\site-packages\urllib3\util\connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\pc\AppData\Roaming\Python\Python39\site-packages\urllib3\connectionpool.py", line 711, in urlopen
    self._prepare_proxy(conn)
  File "C:\Users\pc\AppData\Roaming\Python\Python39\site-packages\urllib3\connectionpool.py", line 1007, in _prepare_proxy
    conn.connect()
  File "C:\Users\pc\AppData\Roaming\Python\Python39\site-packages\urllib3\connection.py", line 363, in connect
    self.sock = conn = self._new_conn()
  File "C:\Users\pc\AppData\Roaming\Python\Python39\site-packages\urllib3\connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x00000280421A17C0>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\site-packages\requests\adapters.py", line 487, in send
    resp = conn.urlopen(
  File "C:\Users\pc\AppData\Roaming\Python\Python39\site-packages\urllib3\connectionpool.py", line 798, in urlopen
    retries = retries.increment(
  File "C:\Users\pc\AppData\Roaming\Python\Python39\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='xueqiu.com', port=443): Max retries exceeded with url: /today (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000280421A17C0>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\PycharmProjects\网络爬虫\逆向爬虫\demo4\demo.py", line 21, in <module>
    response = requests.get('https://xueqiu.com/today', headers=headers).text
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\site-packages\requests\api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\site-packages\requests\api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\site-packages\requests\adapters.py", line 514, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='xueqiu.com', port=443): Max retries exceeded with url: /today (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000280421A17C0>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))
demo.py
import requests

headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Pragma': 'no-cache',
    'Referer': 'https://xueqiu.com/today',
    'Sec-Fetch-Dest': 'document',
    'Sec-Fetch-Mode': 'navigate',
    'Sec-Fetch-Site': 'same-origin',
    'Sec-Fetch-User': '?1',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188',
    'sec-ch-ua': '"Not/A)Brand";v="99", "Microsoft Edge";v="115", "Chromium";v="115"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

response = requests.get('https://xueqiu.com/today', headers=headers).text
print(response)

解决方案

  1. 打开电脑中的设置网络和Internet代理,在手动设置代理中的使用代理服务器,点击编辑
    Python:[WinError 10061] 由于目标计算机积极拒绝,无法连接。,爬虫JS逆向,python,爬虫
  2. 使用代理服务器选择关闭
    Python:[WinError 10061] 由于目标计算机积极拒绝,无法连接。,爬虫JS逆向,python,爬虫

参考地址

https://huaweicloud.csdn.net/63806d62dacf622b8df880b0.html?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Eactivity-8-125711360-blog-122237792.235%5Ev38%5Epc_relevant_sort&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Eactivity-8-125711360-blog-122237792.235%5Ev38%5Epc_relevant_sort&utm_relevant_index=12文章来源地址https://www.toymoban.com/news/detail-733811.html

到了这里,关于Python:[WinError 10061] 由于目标计算机积极拒绝,无法连接。的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包