Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从Python中的url读取数据_Python_Sockets_Url_Urlopen - Fatal编程技术网

无法从Python中的url读取数据

无法从Python中的url读取数据,python,sockets,url,urlopen,Python,Sockets,Url,Urlopen,我认为我的python版本支持urlopen模块 bash-3.2$ ./webscrapping.py Traceback (most recent call last): File "./webscrapping.py", line 6, in ? webpage = urlopen('http://en.wikipedia.org/wiki/Python_(programming_language)').read() File "/usr/lib/python2.4/urllib

我认为我的python版本支持urlopen模块

 bash-3.2$ ./webscrapping.py
 Traceback (most recent call last):
 File "./webscrapping.py", line 6, in ?
 webpage = urlopen('http://en.wikipedia.org/wiki/Python_(programming_language)').read()
 File "/usr/lib/python2.4/urllib.py", line 82, in urlopen
 return opener.open(url)
 File "/usr/lib/python2.4/urllib.py", line 190, in open
 return getattr(self, name)(url)
 File "/usr/lib/python2.4/urllib.py", line 313, in open_http
 h.endheaders()
 File "/usr/lib/python2.4/httplib.py", line 798, in endheaders
 self._send_output()
 File "/usr/lib/python2.4/httplib.py", line 679, in _send_output
 self.send(msg)
 File "/usr/lib/python2.4/httplib.py", line 646, in send
 self.connect()
 File "/usr/lib/python2.4/httplib.py", line 614, in connect
 socket.SOCK_STREAM):
 IOError: [Errno socket error] (8, 'node name or service name not known')
它没有给我任何错误

错误的原因可能是什么?我认为这不是语法错误。 有什么建议吗


谢谢:)

套接字错误表示解析主机名时出错。顺便说一句,使用python中的请求模块访问URL。python 2.7工作正常,请尝试最新版本。如果我使用的是python 2.4.6,我无法在服务器上更新版本:(@user3581172只是出于好奇。这是你的服务器,你不能更新吗?2.4.6也很旧,许多工具和库不再支持它。2.6/2.7前后有一些重要的更改,为它们设计的代码在旧版本中可能不起作用,因此强烈建议进行更新。你能ping
http://en.wikipedia.org/wiki/Python_(编程语言)
来自服务器?是否只有在服务器上时才会失败?
 bash-3.2$ ./webscrapping.py
 Traceback (most recent call last):
 File "./webscrapping.py", line 6, in ?
 webpage = urlopen('http://en.wikipedia.org/wiki/Python_(programming_language)').read()
 File "/usr/lib/python2.4/urllib.py", line 82, in urlopen
 return opener.open(url)
 File "/usr/lib/python2.4/urllib.py", line 190, in open
 return getattr(self, name)(url)
 File "/usr/lib/python2.4/urllib.py", line 313, in open_http
 h.endheaders()
 File "/usr/lib/python2.4/httplib.py", line 798, in endheaders
 self._send_output()
 File "/usr/lib/python2.4/httplib.py", line 679, in _send_output
 self.send(msg)
 File "/usr/lib/python2.4/httplib.py", line 646, in send
 self.connect()
 File "/usr/lib/python2.4/httplib.py", line 614, in connect
 socket.SOCK_STREAM):
 IOError: [Errno socket error] (8, 'node name or service name not known')
bash-3.2$ python 
Python 2.4.6 (#1, Dec 13 2009, 23:45:11) [C] on sunos5            
>>> from urllib import urlopen 
>>>