I have copied this code from the other SO question but i am not able to solve the error i am getting
this is my code
import os
import urllib2
import sys
d = urllib2.urlopen("http://www.google.com.au/logos/2012/new_years_eve_2012_-_english_only-1049005-hp.jpg")
o = open('image.%s' % d.info().gettype(), 'w')
o.write(d.read())
The error is
Traceback (most recent call last): File “./image_test.py”, line 6,
in
o = open(‘image.%s’ % d.info().gettype(), ‘w’) IOError: [Errno 2] No such file or directory: ‘image.image/jpeg’
This is because HTML MIME-types typically include slash, e.g.
image/jpeg. That causes confusion foropen, since slash is a special character used in file system routing.You just have to avoid slash in a file name, for example in a way Joran proposed.
UPDATE In order to make it work in all situations, you have to get a map MIME-type -> file extension. There’s one at Apache: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/conf/mime.types?view=markup . Once you parse it to python dictionary like this:
you will use it the following way: