python - Python 3 requests.get() 在我公司的互联网上不起作用。解决方法?
问题描述
当我在我的个人 wifi 上的 python3 上使用 requests.get 时,它工作正常。然而,我试图自动化的事情发生在工作中。这是我的代码
import requests
res = requests.get('https://automatetheboringstuff.com/files/rj.txt')
工作时出现以下错误
Traceback (most recent call last):
File "C:\Users\\[redacted]\AppData\Roaming\Python\Python37\site-packages\urllib3\connection.py", line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "C:\Users\\[redacted]\AppData\Roaming\Python\Python37\site-packages\urllib3\util\connection.py", line 80, in create_connection
raise err
File "C:\Users\\[redacted]\AppData\Roaming\Python\Python37\site-packages\urllib3\util\connection.py", line 70, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
看起来防火墙阻止我下载任何文件。有没有办法解决?
编辑:我可以从浏览器手动下载这个文件。
解决方案
这可能是由于代理。如果您正在使用代理,请检查您的 PC,如果您记下 ip 并更改您的代码,如下所示:
import requests
proxies = {
"http": "http://<proxy-ip>",
"https": "https://<proxy-ip>",
}
res = requests.get('https://automatetheboringstuff.com/files/rj.txt', proxies=proxies)
推荐阅读
- angular - Angular 生产版本中的无效或意外令牌错误
- php - 访问页面时多次调用 Magento 2 index.php 文件的任何原因?
- javascript - 页面加载时从下到上的图像加载
- f# - 运算符优先级解析中的左递归文法
- excel - 查找功能仅在 VBA 中查找部分值
- css - 我可以跨浏览器获取文本元素的“本机”占位符颜色吗?
- java - Outlook javamail 错误“A3 BAD 用户已通过身份验证但未连接”
- node.js - 与 node.js 共享虚拟主机?
- python - 尝试将多个 csv 文件导入 pandas 时出错
- spring-data-mongodb - 标准 Spring Data MongoDB (1.10.9) 中的口音