如何通过Python urllib.urlretrieve()下载flickr中的图像?
我有一个问题,当从 flickr.com 下载图像时,python 函数 urllib.urlretrieve()
总是返回错误,
[Errno socket error] (10060, 'Operation timed out')
例如:
import urllib
url = "http://farm3.static.flickr.com/2659/4207030547_23e6000d29_o.gif"
urllib.urlretrieve(url,"C://tmp.gif")
我是中国人,我不知道是否“超时”和中国的网速有关系。
现在它无法删除 .gif!我该怎么办?谢谢~~~
任何建议都表示赞赏~~~
I have a problem that when dowloading a image from flickr.com,the python function urllib.urlretrieve()
always return an error
[Errno socket error] (10060, 'Operation timed out')
for example:
import urllib
url = "http://farm3.static.flickr.com/2659/4207030547_23e6000d29_o.gif"
urllib.urlretrieve(url,"C://tmp.gif")
I am Chinese,and I dont know if the "time out" has anything to do with the speed of the the internet in China.
Now it falied in downing the .gif! what should i do about this? THX~~~
Any suggestion is appreciated~~~
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我无法重现。
完全相同的代码下载了图片。
我正在使用 python 2.7
它必须与服务器(当时)或与您的互联网连接有关。
I can't reproduce.
The exact same code downloaded the picture.
I'm using python 2.7
It has to do either with the server (at that time) or with your internet connection.
考虑使用
urllib2
库,它允许您指定超时(在 Python 2.6+ 中)。Consider using the
urllib2
library instead, which allows you to specify the timeout (in Python 2.6+).你无法从 flickr 下载图片的原因是,中国有一堵可怕的墙挡住了你!你可以尝试在你的电脑上使用一个全局运行的VPN(这样你的python程序也运行在这个VPN环境下),
或者,
您在
requests
中设置代理,然后您可以从那些被中国屏蔽的网站下载图像。The reason you cannot download the image from flickr is that, China has a freaking WALL that's blocking you! You can try to use a VPN that works globally on your computer (so that your python program also runs under this VPN environment),
or,
you set up the proxies in, let's say
requests
, then you can download images from those websites that are blocked from China.尝试“获取”方法。我最近不得不做同样的事情,我用以下方法解决了问题:
Try the "get" method. I have recently had to do the same thing and I solved the problem with the following: