- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
import requests
import urllib3
from time import sleep
from sys import argv
script, filename = argv
http = urllib3.PoolManager()
datafile = open('datafile.txt','w')
crawl = ""
with open(filename) as f:
mylist = f.read().splitlines()
def crawlling(x):
for i in mylist:
domain = ("http://" + "%s") % i
crawl = http.request('GET','%s',preload_content=False) % domain
for crawl in crawl.stream(32):
print crawl
sleep(10)
crawl.release_conn()
datafile.write(crawl.status)
datafile.write('>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n')
datafile.write(crawl.data)
datafile.close()
return x
crawlling(crawl)
_______________________________________________________________________
Extract of domain.txt file:
fjarorojo.info
buscadordeproductos.com
我是 python 的新手,所以请耐心等待:我正在尝试从 URL 获取内容,但它抛出错误。此外,它在浏览器中运行良好。脚本的对象是从 domain.txt 文件中获取数据并对其进行迭代并获取内容并将其保存在文件中。
Getting this error:
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='%s',
port=80): Max retries exceeded with url: / (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7ff45e4f9cd0>: Failed to establish a new connection: [Errno -2] Name or
service not known',))
最佳答案
这一行是问题所在:
crawl = http.request('GET','%s',preload_content=False) % domain
现在您正在尝试向域 %s
发出请求,该域不是有效域,因此出现错误“Name or服务未知”。
应该是:
crawl = http.request('GET', '%s' % domain, preload_content=False)
或者更简单地说:
crawl = http.request('GET', domain, preload_content=False)
此外,与您发布的错误无关,这些行也可能会导致问题:
for crawl in crawl.stream(32):
print crawl
sleep(10)
crawl.release_conn() # <--
您在循环中释放连接,因此循环将无法在第二次迭代中产生预期结果。相反,您应该只在完成请求后释放连接。 More details here .
关于Python:HTTPConnectionPool(主机 ='%s',端口=80):,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40054711/
我有一个像这样的 python 脚本: #!/usr/bin/python import sys import requests if len(sys.argv) ' % (sys.argv[0])
我正在使用 urllib3 的 HTTPConnectionPool 进行发布请求。这里的代码 http://something.com/file.php 有 2 重定向。请求完成后,我在 heade
在 Linux 集群上,我收到此请求错误: ConnectionError: HTTPConnectionPool(host='andes-1-47', port=8181): Max retries
我编写了以下 python 脚本来检查前缀和后缀的可能排列是否作为网站 url 存在: import requests prefix = ['test', 'trial','demo','check'
我想知道我的请求是否被网站停止,我需要设置代理。我首先尝试关闭http的连接,但我失败了。我也尝试测试我的代码,但现在似乎没有输出。Mybe我使用代理一切都会好吗?这是代码。 import reque
import requests import urllib3 from time import sleep from sys import argv script, filename = argv h
当运行nosetests时,使用Flask-test我不断收到此错误: File "/app/env/local/lib/python2.7/site-packages/twill/browser.p
我在 session 中使用 python 请求库: def _get_session(self): if not self.session: self.session = r
您好,我正在使用 pywebhdfs python 库。我通过调用并尝试在 HDFS 上创建文件来连接 EMR。我遇到了以下异常,这似乎与我正在执行的操作无关,因为我在这里没有达到任何连接限制。是因为
我正在使用 H2O 的机器学习包(随机森林)。 有时,我会收到此错误: H2OConnectionError: Unexpected HTTP error: HTTPConnectionPool(ho
我有一个在服务器上运行的ElasticSearch实例。当我尝试使用多处理对巨大的语料库建立索引时,出现很多超时错误。看来EasticSearch只能处理少量请求。我遵循了ElasticSearch网
我刚刚在 python 3.6.1 上安装了 h2o 模块... (Java 版本 8 更新 74(内部版本 1.8.0_74-b02) Windows 版本 10 专业版) 当我给出命令 h2o i
当我尝试从 Django 应用程序调用在端口 5000 上使用 docker-compose 部署的服务时遇到此错误,该应用程序也在端口 8000 上使用 docker-compose 部署。我也在使
我有一个 Elastic Search 服务器,我可以从实时网站并通过 Django 管理命令对其进行查询。管理命令在格林威治标准时间凌晨 3 点使用 celerybeat 运行,以同步来自外部服务的
我有一个问题:我想测试“select”和“input”。我可以像下面的代码那样写吗:原代码: 12 class Sinaselecttest(unittest.TestCase): 13 14
我有一个问题:我想测试“select”和“input”。我可以像下面的代码那样写吗:原始代码: 12 class Sinaselecttest(unittest.TestCase): 13 14
我有一个问题:我想测试“select”和“input”。我可以像下面的代码那样写吗:原始代码: 12 class Sinaselecttest(unittest.TestCase): 13 14
我正在尝试在 Django 之间进行通信和 Python文件,但我收到以下错误: requests.exceptions.ConnectionError: HTTPConnectionPool(hos
我正在使用 python 使 2 个 API 在它们之间进行通信,我进行了测试,两个 API 都可以自己正常工作,当我尝试向 API A(用 Flask 制作)发送请求以便 A 可以通过时,问题就出现
我正在尝试用 selenium 抓取网站的几页并使用结果,但是当我运行该函数两次时 [WinError 10061] No connection could be made because the t
我是一名优秀的程序员,十分优秀!