- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 python 的 urllib 和中断的互联网连接方面遇到了一些问题:在没有事件互联网连接的情况下第一次调用它时,我永远无法从 urllib.request.urlopen 获取信息。以下工作正常:
> python
>>> import urllib.request
>>> urllib.request.urlopen("http://www.google.com")
<http.client.HTTPResponse object at 0x7f6f54681438>
#Now disable internet connection:
> sudo ip link set enp4s0 down
>>> urllib.request.urlopen("http://www.google.com")
Traceback (most recent call last):
File "/usr/lib/python3.4/urllib/request.py", line 1189, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "/usr/lib/python3.4/http/client.py", line 1090, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.4/http/client.py", line 1128, in _send_request
self.endheaders(body)
File "/usr/lib/python3.4/http/client.py", line 1086, in endheaders
self._send_output(message_body)
File "/usr/lib/python3.4/http/client.py", line 924, in _send_output
self.send(msg)
File "/usr/lib/python3.4/http/client.py", line 859, in send
self.connect()
File "/usr/lib/python3.4/http/client.py", line 836, in connect
self.timeout, self.source_address)
File "/usr/lib/python3.4/socket.py", line 491, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.4/socket.py", line 530, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/urllib/request.py", line 153, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.4/urllib/request.py", line 455, in open
response = self._open(req, data)
File "/usr/lib/python3.4/urllib/request.py", line 473, in _open
'_open', req)
File "/usr/lib/python3.4/urllib/request.py", line 433, in _call_chain
result = func(*args)
File "/usr/lib/python3.4/urllib/request.py", line 1215, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/usr/lib/python3.4/urllib/request.py", line 1192, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>
#Reenable internet connection:
> sudo ip link set enp4s0 up #and wait a bit
>>> urllib.request.urlopen("http://www.google.com")
<http.client.HTTPResponse object at 0x7f6f5468c898>
到目前为止一切顺利。现在完全相同,但没有第一次调用 urlopen:
> python
>>> import urllib.request
# do not call urlopen before internet is down...
#Now disable internet connection:
> sudo ip link set enp4s0 down
>>> urllib.request.urlopen("http://www.google.com")
[exactly the same error message as above]
#Reenable internet connection:
> sudo ip link set enp4s0 up #and wait a bit
#Ensure internet connection is up
> ip link show enp4s0 up
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP [...]
>>> urllib.request.urlopen("http://www.google.com")
[exactly the same error message as above]
#What's the problem? The internet connection IS up
#However:
> host www.google.com
www.google.com has address 173.194.69.104
[...]
>>> urllib.request.urlopen("http://173.194.69.104")
<http.client.HTTPResponse object at 0x7f3116a72e48>
所以我想它必须对 DNS(-缓存)做些什么?
最后是关于我的系统的一些信息:
> python --version
Python 3.4.1
> uname -a
Linux charon 3.15.3-1-ARCH #1 SMP PREEMPT Tue Jul 1 07:32:45 CEST 2014 x86_64 GNU/Linux
抱歉奇怪的格式。我混淆了“普通”(以“>”为前缀)和 python(以“>>>”为前缀)shell 命令以使确切的命令序列清晰(这显然发生在不同的终端)。
最佳答案
您正在运行 well-known glibc problem .人们可以争论这是对 glibc 的误用还是 glibc 在这里做错了什么。 res_init
不是 POSIX 的一部分,而是源自 BSD 的接口(interface),因此很难以平台无关的方式正确执行。
对于这个问题似乎没有针对 python 的错误报告,所以你可能想要 file one .
作为一种变通方法,您可以使用 ctypes
自己调用 res_init
,但我不知道该怎么做.
关于互联网连接中断的 Python 的 urllib.request.urlopen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24588010/
如有任何帮助,我将不胜感激。我使用 Python 3.4.1 并尝试导入 urllib.request 和 urllib.parse。没有成功。我总是收到: Traceback (most recen
我正在尝试一个教程代码,它从一个网站获取 html 代码并打印出来。我在 ubuntu 上使用 python 3.4.0。代码: import urllib.request page = urllib
根据这个answer几年前给出了一个相同的问题,Javascript 中的 encodeURIComponent(str) 应该等同于 Python 中的 urllib.quote(str, safe
1。弃用问题 在 Python 3.7 中,我使用 urllib.request.urlretrieve(..) 函数从 URL 下载了一个大文件。在文档 ( https://docs.python.
在 python 3 中,导入时出现此错误:没有名为“urllib.request.urlretrieve”的模块; “urllib.request”不是一个包 import urllib impor
import urllib print urllib.urlopen('http://www.reefgeek.com/equipment/Controllers_&_Monitors/Neptune
我在 gooogle colab 中使用来自 parselmouth 的 praat,在导入 from parselmouth.praat import call 时出现此错误 /usr/local/
是否有与 Python 的 urllib.parse.quote() 等效的 JavaScript 函数?和 urllib.parse.unquote() ? 我遇到的最接近的是encodeURI()
这个问题在这里已经有了答案: Importing installed package from script with the same name raises "AttributeError: m
Python 的 urllib.quote 和 urllib.unquote 在 Python 2.6.5 中无法正确处理 Unicode。这就是发生的事情: In [5]: print urllib
这个问题在这里已经有了答案: How to route urllib requests through the TOR network? [duplicate] (3 个回答) 关闭6年前。 示例代码
我正在制作一些简单的 python 帖子脚本,但效果不佳。 有两部分必须登录。 第一次登录使用' http://mybuddy.buddybuddy.co.kr/userinfo/UserInfo.a
我有以下脚本: from currency_converter import CurrencyConverter test = CurrencyConverter('http://www.ecb.eu
我正在编写一个小工具来监控学校的开课情况。 我编写了一个 python 脚本,每隔几分钟就会从每个部门获取当前类(class)的可用性。 该脚本一直正常运行,直到大学网站开始返回以下内容: SIS S
为什么下面的结果会出错? import re from urllib import quote as q s = re.compile(r'[^a-zA-Z0-9.: ^*$@!+_?-]') s.s
我正在开发一个网络爬虫来自动下载巴西网站上的一些文档。并且它使用了一些未知的编码(head 标签中没有定义字符集)。 人们只需付出很少的努力就可以阅读这些文档。但真正的问题是,列出文档的页面使用的链接
我有一个程序,我需要打开许多网页并下载其中的信息。然而,这些信息位于页面中间,需要很长时间才能找到。有没有办法让 urllib 只检索 x 行?或者,如果没有别的事,之后就不加载信息? 我在 Mac
我有一个脚本,使用 Urllib 打开我安装了谷歌分析的网页。我的问题是,为什么如果我执行脚本,GA 上不会显示访问次数? 最佳答案 Google Analytics 脚本是 JavaScript 代
我正在尝试下载航类搜索结果,但我不断收到一个与通过右键单击并手动存储网站获得的文件不同的文件。我已经尝试过 urllib 、 urllib2 以及我在这里找到的每个命令都无济于事。 这是一个 MWE:
我最近用Python(Windows 64位v3.3.1)编写了一个程序,并试图将其移植到D。我遇到的问题是我使用了urllib Python 中的模块,特别是 urllib.request.Requ
我是一名优秀的程序员,十分优秀!