Downloading images from PycURL broke me

I fight picurle. These are my headers:

headers.append('User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0')
headers.append('Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
headers.append('Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3')
headers.append('Accept-Encoding: gzip, deflate')
headers.append('Accept-Charset: UTF-8,*')
headers.append('Connection: Keep-Alive')

Original: http://dl.dropbox.com/u/25733986/test.jpg

What I get: http://dl.dropbox.com/u/25733986/test_kaputt.jpg

As you can see, the one I get with pycurl is broken. If I compare them with a text comparison tool, it tells me that they are the same. (There was a difference in the outline of the lines where the original had only LF, and the broken one had CRLF, but I changed this and now I have identical images still broken)

The host I'm loading from is not the reason. I tried to do the same from dropbox and local apache. Both did not work.

This is how I save the image:

self.buffer = StringIO.StringIO()
# other curl options like ssl, cookies, followlocation and GET Request URL Setup to the Image: http://dl.dropbox.com/u/25733986/test.jpg
self.curl.setopt(pycurl.WRITEFUNCTION, self.buffer.write)
# -> curl.perform()
f = open("temp/resources/%s" % (filename,), 'w')
f.write(self.buffer.getvalue())
f.close()

I would be glad if anyone has any suggestions on this, so I can find my mistake.

+3
source share
1 answer

, , , , , , .

.

f = open("temp/resources/%s" % (filename,), 'wb')

, - -.

, stackoverflow, .:)

+5

All Articles