[Tutor] Saving data as jpg file

Johan Geldenhuys johan at accesstel.com.au
Sun Jun 12 00:53:31 CEST 2011


Hi,

I have a Axis IP camera that I can send a HTTP command to and the data
returned is the jpg image.

When I get this data, I want to save it as a .jpg file, but I think my
encoding is not correct, because the image is all distorted.

 

I looked at using PIL, but the device I will install my script on can't be
used to install other packages like this. I'll have to include the modules
in my own folder.

 

Here is my simple code that I started testing with.

 

 

"""

import urllib2

 

# Create an OpenerDirector with support for Basic HTTP Authentication...

auth_handler = urllib2.HTTPBasicAuthHandler()

auth_handler.add_password('.', '192.168.10.190', 'root', 'pass')

opener = urllib2.build_opener(auth_handler)

 

# ...and install it globally so it can be used with urlopen.

urllib2.install_opener(opener)

 

return_object =
urllib2.urlopen('http://192.168.10.190/axis-cgi/jpg/image.cgi?resolution=320
x240&squarepixel=1')

 

html_content = return_object.read()

img_file = "E:\work\img1.jpg"

f = open(img_file, 'w')

f.write(html_content)

f.close()

""" 

 

Any ideas what type of encoding I have to use if that is the problem?

 

Thanks

 

Johan

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110612/ec2abd1b/attachment.html>


More information about the Tutor mailing list