Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2

Piet van Oostrum piet at vanoostrum.org
Thu Sep 26 14:44:30 EDT 2013


Nils Bunger <nilsbunger at gmail.com> writes:

> Hi Neil, 
>
> Thanks for looking at this.  
>
> I'm trying to create a multipart MIME for an HTTP POST request, not an
> email. This is for a third-party API that requires a multipart POST
> with a binary file, so I don't have the option to just use a different
> encoding.
>
> Multipart HTTP is standardized in HTTP 1.0 and supports binary parts.
> Also, no one will re-interpret contents of HTTP on the wire, as binary
> is quite normal in HTTP.
>
> The issue seems to be some parts of the python MIME encoder still
> assume it's for email only, where everything would be b64 encoded.
>
> Maybe I have to roll my own to create a multipart msg with a binary
> file? I was hoping to avoid that.

The email MIME stuff is not really adapted for HTTP. I would advise to
use the Requests package (http://docs.python-requests.org/en/latest/) or
the Uploading Files part from Doug Hellmann's page
(http://doughellmann.com/2009/07/pymotw-urllib2-library-for-opening-urls.html).
This is for Python2; I can send you a Python3 version if you want.
-- 
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]



More information about the Python-list mailing list