Any idea why a server might be returning the message, in json format, 
"Malformed Upload"? The image is gzipped as the server requires... Someone on 
another forum said that he thinks Python requests automatically gzips?

I have the code working in vb.net... no idea why it wont work in Python.

This is my code.

def uploadPhoto(url, sid, dafile):

headers = {'User-Agent':useragent, 
                     'Session-Id':sessionid, 
                     'Content-Type':'image/jpeg', 
                     'Accept-Encoding':'gzip, deflate'}

f_in = open(dafile, 'rb')
f_out = gzip.open('/Users/Paul/Desktop/scripts/pic.jpg.gz', 'wb')
f_out.writelines(f_in)
f_out.close()
f_in.close()

files = {('Image', open('/Users/Paul/Desktop/scripts/pic.jpg.gz', 'rb'))}
r = requests.post(url, headers=headers, proxies=proxies, files=files)    

print r.status_code
print r.request.headers
return str(r.text)



The server replies with:

{"message":"Malformed Upload","code":1012}
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to