- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我目前对我使用 Python 发出的任何请求都收到网络无法访问错误。无论我使用的是 urllib 库还是 requests 库。
经过更多研究后,它很可能是由错误设置的 ipv6 隧道引起的,该隧道似乎仍处于事件状态:
$ ip -6 addr show
$ ip -6 route
default dev wlan0 metric 1
一些上下文:我正在运行 Archlinux 并今天更新了系统,尽管今天似乎没有任何与 python 相关的特殊更新。我也在 virtualenv 下运行它,但是其他 virtualenvs 和在 virtualenv 之外使用我的 Python 也有同样的问题。
我正在使用 VPN,但如果没有 VPN,我也会遇到同样的错误。我也尝试重新启动 PC,哈哈,这通常有助于解决任何问题,哈哈,但也没有帮助。
我感觉它可能与 Archlinux 相关,但我不确定。
这是我之前尝试设置 ipv6 隧道的方法:
sudo modprobe ipv6
sudo ip tunnel del sit1
sudo ip tunnel add sit1 mode sit remote 59.66.4.50 local $ipv4
sudo ifconfig sit1 down
sudo ifconfig sit1 up
sudo ifconfig sit1 add 2001:da8:200:900e:0:5efe:$ipv4/64
sudo ip route add ::/0 via 2001:da8:200:900e::1 metric 1
也用到了这个命令:
ip -6 addr add 2001:0db8:0:f101::1/64 dev eth0
在删除/etc/systemctl.conf 中的 ipv6 行后更新 3,一些 url 开始工作:
>>> urllib2.urlopen('http://www.google.com')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 400, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 418, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1207, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1177, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 101] Network is unreachable>
>>> urllib2.urlopen('http://baidu.com')
<addinfourl at 27000560 whose fp = <socket._fileobject object at 0x7f4d1fed5e50>>
这是 ipython 的错误日志。
In [1]: import urllib2
In [2]: urllib2.urlopen('http://google.com')
---------------------------------------------------------------------------
URLError Traceback (most recent call last)
/home/samos/<ipython console> in <module>()
/usr/lib/python2.7/urllib2.py in urlopen(url, data, timeout)
124 if _opener is None:
125 _opener = build_opener()
--> 126 return _opener.open(url, data, timeout)
127
128 def install_opener(opener):
/usr/lib/python2.7/urllib2.py in open(self, fullurl, data, timeout)
398 req = meth(req)
399
--> 400 response = self._open(req, data)
401
402 # post-process response
/usr/lib/python2.7/urllib2.py in _open(self, req, data)
416 protocol = req.get_type()
417 result = self._call_chain(self.handle_open, protocol, protocol +
--> 418 '_open', req)
419 if result:
420 return result
/usr/lib/python2.7/urllib2.py in _call_chain(self, chain, kind, meth_name, *args)
376 func = getattr(handler, meth_name)
377
--> 378 result = func(*args)
379 if result is not None:
380 return result
/usr/lib/python2.7/urllib2.py in http_open(self, req)
1205
1206 def http_open(self, req):
-> 1207 return self.do_open(httplib.HTTPConnection, req)
1208
1209 http_request = AbstractHTTPHandler.do_request_
/usr/lib/python2.7/urllib2.py in do_open(self, http_class, req)
1175 except socket.error, err: # XXX what error?
1176 h.close()
-> 1177 raise URLError(err)
1178 else:
1179 try:
URLError: <urlopen error [Errno 101] Network is unreachable>
我可以从网络浏览器正常访问 google.com,我很确定网络可以访问。
最佳答案
您确定您没有使用任何 HTTP 代理服务器访问互联网吗?
尝试将浏览器中的网络设置更改为无代理,并检查它是否仍在连接到互联网。
如果您正在使用代理(假设代理地址为 http://yourproxy.com),请尝试执行此操作以检查是否可以解决问题。
import urllib2
proxy = urllib2.ProxyHandler({'http': 'yourproxy.com'})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
urllib2.urlopen('http://www.google.com')
关于Python 总是返回 Network is unreachable because of old ipv6 configuration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10450776/
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
在编码时,我问了自己这个问题: 这样更快吗: if(false) return true; else return false; 比这个? if(false) return true; return
如何在逻辑条件下进行“返回”? 在这样的情况下这会很有用 checkConfig() || return false; var iNeedThis=doSomething() || return fa
这是我的正则表达式 demo 如问题所述: 如果第一个数字是 1 则返回 1 但如果是 145 则返回 145 但如果是 133 则返回 133 样本数据a: K'8134567 K'81345678
在代码高尔夫问答部分查看谜题和答案时,我遇到了 this solution返回 1 的最长和最晦涩的方法 引用答案, int foo(void) { return! 0; } int bar(
我想在下面返回 JSON。 { "name": "jackie" } postman 给我错误。说明 Unexpected 'n' 这里是 Spring Boot 的新手。 1日龄。有没有正确的方法来
只要“is”返回 True,“==”不应该返回 True 吗? In [101]: np.NAN is np.nan is np.NaN Out[101]: True In [102]: np.NAN
我需要获取所有在 6 号或 7 号房间或根本不在任何房间的学生的详细信息。如果他们在其他房间,简单地说,我不希望有那个记录。 我的架构是: students(roll_no, name,class,.
我有一个表单,我将它发送到 php 以通过 ajax 插入到 mysql 数据库中。一切顺利,php 返回 "true" 值,但在 ajax 中它显示 false 消息。 在这里你可以查看php代码:
我在 Kotlin 中遇到了一个非常奇怪的无法解释的值比较问题,以下代码打印 假 data class Foo ( val a: Byte ) fun main() { val NUM
请注意,这并非特定于 Protractor。问题在于 Angular 2 的内置 Testability service Protractor 碰巧使用。 Protractor 调用 Testabil
在调试窗口中,以下表达式均返回 1。 Application.WorksheetFunction.CountA(Cells(4 + (i - 1) * rows_per_record, 28) & "
我在本地使用 jsonplaceholder ( http://jsonplaceholder.typicode.com/)。我正在通过 extjs rest 代理测试我的 GET 和 POST 调用
这是 Postman 为成功调用我的页面而提供的(修改后的)代码段。 var client = new RestClient("http://sub.example.com/wp-json/wp/v2
这个问题在这里已经有了答案: What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must
我想我对 C 命令行参数有点生疏。我查看了我的一些旧代码,但无论这个版本是什么,都会出现段错误。 运行方式是 ./foo -n num(其中 num 是用户在命令行中输入的数字) 但不知何故它不起作用
我已经编写了一个类来处理命名管道连接,如果我创建了一个实例,关闭它,然后尝试创建另一个实例,调用 CreateFile() 返回 INVALID_HANDLE_VALUE,并且 GetLastErro
即使 is_writable() 返回 true,我也无法写入文件。当然,该文件存在并且显然是可读的。这是代码: $file = "data"; echo file_get_contents($fil
下面代码中的变量 $response 为 NULL,尽管它应该是 SOAP 请求的值。 (潮汐列表)。当我调用 $client->__getLastResponse() 时,我从 SOAP 服务获得了
我一直在网上的不同论坛上搜索答案,但似乎没有与我的情况相符的... 我正在使用 Windows 7,VS2010。 我有一个使用定时器来调用任务栏刷新功能的应用程序。在该任务栏函数中包含对 LoadI
我是一名优秀的程序员,十分优秀!