urllib2.urlopen()打开mp3链接时,报错
请教各位,准备在VOA的官网上正常mp3文件,在用 urllib2.urlopen()下载mp3类型文件时,报了 URLError。有可能是哪些原因造成的呢?多谢各位。
使用的代码如下:
urllib2.urlopen('http://realaudio.rferl.org/voa/LERE/2013/07/19/6d07939b-45fc-4984-92b5-7f9ccc978ac5.mp3')
已经进行的一些尝试:
- 链接是浏览器中是可以正常访问的。
- 在chrome中修改user-agent为'aaa',也可以正常下载,应该可以排除网站限制了非浏览器访问。
- 下载html类型的链接正常。
感谢@依云的提醒,以下是Traceback:
>>> urllib2.urlopen('http://realaudio.rferl.org/voa/LERE/2013/07/19/6d07939b-45fc-4984-92b5-7f9ccc978ac5.mp3')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
urllib2.urlopen('http://realaudio.rferl.org/voa/LERE/2013/07/19/6d07939b-45fc-4984-92b5-7f9ccc978ac5.mp3')
File "C:\Python27\lib\urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 404, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 422, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1214, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "C:\Python27\lib\urllib2.py", line 1187, in do_open
r = h.getresponse(buffering=True)
File "C:\Python27\lib\httplib.py", line 1045, in getresponse
response.begin()
File "C:\Python27\lib\httplib.py", line 409, in begin
version, status, reason = self._read_status()
File "C:\Python27\lib\httplib.py", line 365, in _read_status
line = self.fp.readline(_MAXLINE + 1)
File "C:\Python27\lib\socket.py", line 476, in readline
data = self._sock.recv(self._rbufsize)
error: [Errno 10054]
螺螺螺螺螺螺螺
11 years, 5 months ago