kmj
03-11-2002, 10:23 PM
just wondering if anyone here has used httplib to access gif files on the interweb. I seem to be able to download them without problems, but they always seem to be corrupt.
Here's the code I'm using. A shiny nickel to anyone who can tell my why my gifs come out corrupt.
from httplib import *
h = HTTPConnection('www.python.org')
h.request('GET', '/pics/python265.gif')
g = h.getresponse()
print g.status # should be 200
t = g.read()
f = open ('d:\\myfile.gif', 'w') #it's at this point that I realize I'm a moron
f.close()
And of course, as I'm typing this I see
f = open ('d:\\myfile.gif', 'w')
and realize it should be
f = open ('d:\\myfile.gif', 'wb')
so that it's outputted as binary data, not text, and I go test it and it works fine. :) well then Thank you all for your help, as a reward for being so helpful, take the above code and use it as you wish. :)
Here's the code I'm using. A shiny nickel to anyone who can tell my why my gifs come out corrupt.
from httplib import *
h = HTTPConnection('www.python.org')
h.request('GET', '/pics/python265.gif')
g = h.getresponse()
print g.status # should be 200
t = g.read()
f = open ('d:\\myfile.gif', 'w') #it's at this point that I realize I'm a moron
f.close()
And of course, as I'm typing this I see
f = open ('d:\\myfile.gif', 'w')
and realize it should be
f = open ('d:\\myfile.gif', 'wb')
so that it's outputted as binary data, not text, and I go test it and it works fine. :) well then Thank you all for your help, as a reward for being so helpful, take the above code and use it as you wish. :)