Saving image in python using urllib

901 Views Asked by At

I am trying to save an image from the web using urllib and I keep getting this error :

[Wed Oct 17 10:03:43 2012] [error] [client 223.232.227.124] urllib.urlretrieve(image,ban)
[Wed Oct 17 10:03:43 2012] [error] [client 223.232.227.124]   File "/usr/lib/python2.6/urllib.py", line 93, in urlretrieve
[Wed Oct 17 10:03:43 2012] [error] [client 223.232.227.124]     return _urlopener.retrieve(url, filename, reporthook, data)
[Wed Oct 17 10:03:43 2012] [error] [client 223.232.227.124]   File "/usr/lib/python2.6/urllib.py", line 243, in retrieve
[Wed Oct 17 10:03:43 2012] [error] [client 223.232.227.124]     tfp = open(filename, 'wb')
[Wed Oct 17 10:03:43 2012] [error] [client 223.232.227.124] IOError: [Errno 13] Permission denied: '/public/env/lib/python2.6/site-packages/project-0.0-py2.6.egg/project/images/series/graphical/104281-g2.jpg'

The code :

ban='/public/env/project/project/images/series/%s'%(banner)
image='http://www.thetvdb.com/banners/%s'%(banner)
urllib.urlretrieve(image,ban)

The code is working perfectly fine on my localhost using Pyramid waitress server as well as using mod_wsgi too but not on production server.

I am using Pyramid framework for development.

1

There are 1 best solutions below

5
On

This is a permissions issue. You do not have permission to write to the place that you are trying to in the server. Try someother location where you have permissions or set the proper permissions to that directory.

urlretrieve(url, filename=None, reporthook=None, data=None)

The second argument is the filename you want to write to. Since you are running from webapp, the process which is running the webapp should have permission to the location where you trying to write.