Question on using urllib

Peter Otten __peter__ at
Thu Nov 11 18:37:27 CET 2010

Olivier Scalbert wrote:

> Sorry if this question is not 100% python related, it is also related to
> http or html ...
> Everything takes place in this page:
> With the following program, I can download the 2 small meteo images,
> without any problem:
> import urllib
> "meteo1.jpg")
> urllib.urlretrieve("",
> "meteo2.jpg")
> But I would like to download the main background picture.
> By looking inside the html page, it seems it's url is:

> I try to download it with python:
> urllib.urlretrieve("",
> "picture.jpg")

The problem is indeed not Python-related. The provider of the images doesn't 
like what you're trying to do and verifies the referer, i. e. that the page 
you claim to be coming from is acceptable. Here's one way to satisfy that 

>>> from urllib2 import Request, urlopen
>>> r = Request("", 
>>> img = urlopen(r).read()
>>> with open("tmp.jpg", "w") as f: f.write(img)

Now if you are using that workaround a lot he may come up with more 
sophisticated techniques. So dont ;)


More information about the Python-list mailing list