urllib2.urlopen()打开mp3链接报error: [Errno 10054],,请教各位,准备在VOA的
urllib2.urlopen()打开mp3链接报error: [Errno 10054],,请教各位,准备在VOA的
请教各位,准备在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]
如果在*nix 我一般直接用 wget 方便...
可以用httplib2包进行连接,一点是能够防止服务器检测,而是可以设置相关的代理。https://code.google.com/p/httplib2/
可以设置socks,http://socksipy.sourceforge.net/
import httplib2import sockshttplib2.debuglevel=4h = httplib2.Http(proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP, 'localhost', 8000))r,c = h.request("http://bitworking.org/news/")
详细用法可以参考https://code.google.com/p/httplib2/wiki/Examples
代码最先是在Windows下运行的。尝试在linux运行时,报错信息中有“Connection been reset by peers”,所以推测是GFW的问题。
到linode机器上验证了下,运行OK。
结论:这个问题是GFW的问题,跟代码没什么关系。
编橙之家文章,
相关内容
- Python VLfeat图像库找不到python接口,vlfeat图像库,vlfeat这
- Python pyquery和beautifulsoup哪款使用者多,,之前使用过be
- 参考核心编程的函数装饰器报错'NoneType' object is not ca
- 下面这段python代码中fahr未定义是何含义,pythonfahr,cel
- Python Requests库上传文件中文文件名处理方法是什么,
- Web方向学习有哪些好书籍推荐,Web方向学习书籍,有没有
- Python RSA公钥加密结果不同求解,pythonrsa,首先使用rsa生
- 求Python获取http内容并循环输出新内容的方法,python获取
- MySQL小问题,fetchone怎么返回到dict中的方法?,fetchonedic
- 关于python分布式项目工程之间模块依赖问题,python模块
评论关闭