Created
February 23, 2009 07:12
-
-
Save code/68841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Got hit by this crazy bug in python | |
result = urlfetch.fetch('http://domain/image.jpg') | |
multipart_upload_body = "multi part %s upload string" % result.content | |
# This caused an invalid ascii error since result.content is binary and python wanted to convert it to ascii. | |
# The solution was not obvious, the only way we found to do it was to create a byte array then write to it like a buffer | |
buffer = array.array("B") # B = unsigned bytes | |
buffer.fromstring("multi part ") | |
buffer.fromstring(result.content) | |
buffer.fromstring(" upload string") | |
multipart_upload_body = buffer.tostring() | |
# works! string handling in python 2.x is a little odd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment