Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94944 > unrolled thread

Parsing multipart HTTP response

Started byGilles Lenfant <gilles.lenfant@gmail.com>
First post2015-08-03 08:01 -0700
Last post2015-08-03 10:15 -0700
Articles 4 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Parsing multipart HTTP response Gilles Lenfant <gilles.lenfant@gmail.com> - 2015-08-03 08:01 -0700
    Re: Parsing multipart HTTP response Gilles Lenfant <gilles.lenfant@gmail.com> - 2015-08-03 08:05 -0700
    Re: Parsing multipart HTTP response Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-08-03 16:39 +0100
      Re: Parsing multipart HTTP response Gilles Lenfant <gilles.lenfant@gmail.com> - 2015-08-03 10:15 -0700

#94944 — Parsing multipart HTTP response

FromGilles Lenfant <gilles.lenfant@gmail.com>
Date2015-08-03 08:01 -0700
SubjectParsing multipart HTTP response
Message-ID<648c131d-6315-4f83-88f0-b87bf3b530a9@googlegroups.com>
Hi,

I searched without succeeding a Python resource that is capable of parsing an HTTP multipart/mixed response stream, preferably as a generator that yields headers + content for each part.

Google and friends didn't find or I didn't use the appropriate term.

Any hint will be appreciated.
--
Gilles Lenfant

[toc] | [next] | [standalone]


#94945

FromGilles Lenfant <gilles.lenfant@gmail.com>
Date2015-08-03 08:05 -0700
Message-ID<90e7b566-0ba4-44f7-95d7-13ed69dd1112@googlegroups.com>
In reply to#94944
Le lundi 3 août 2015 17:01:40 UTC+2, Gilles Lenfant a écrit :
> Hi,
> 
> I searched without succeeding a Python resource that is capable of parsing an HTTP multipart/mixed response stream, preferably as a generator that yields headers + content for each part.
> 
> Google and friends didn't find or I didn't use the appropriate term.
> 
> Any hint will be appreciated.
> --
> Gilles Lenfant

Ah, aiohttp does something similar to what I need but requires Python 3.3 + when I'm stuck with Pyton 2.7 on that project.

[toc] | [prev] | [next] | [standalone]


#94947

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-08-03 16:39 +0100
Message-ID<mailman.1195.1438616367.3674.python-list@python.org>
In reply to#94944
On 03/08/2015 16:01, Gilles Lenfant wrote:
> Hi,
>
> I searched without succeeding a Python resource that is capable of parsing an HTTP multipart/mixed response stream, preferably as a generator that yields headers + content for each part.
>
> Google and friends didn't find or I didn't use the appropriate term.
>
> Any hint will be appreciated.
> --
> Gilles Lenfant
>

Hardly my field but how about:-

https://pypi.python.org/pypi/requests-toolbelt/0.3.1
https://pypi.python.org/pypi/multipart/

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#94951

FromGilles Lenfant <gilles.lenfant@gmail.com>
Date2015-08-03 10:15 -0700
Message-ID<85fe942e-5318-4343-aa23-04033b7d270c@googlegroups.com>
In reply to#94947
Le lundi 3 août 2015 17:39:57 UTC+2, Mark Lawrence a écrit :
> On 03/08/2015 16:01, Gilles Lenfant wrote:
> > Hi,
> >
> > I searched without succeeding a Python resource that is capable of parsing an HTTP multipart/mixed response stream, preferably as a generator that yields headers + content for each part.
> >
> > Google and friends didn't find or I didn't use the appropriate term.
> >
> > Any hint will be appreciated.
> > --
> > Gilles Lenfant
> >
> 
> Hardly my field but how about:-
> 
> https://pypi.python.org/pypi/requests-toolbelt/0.3.1
> https://pypi.python.org/pypi/multipart/
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Thanks Mark,

"multipart" is close to what I need and will give me some inpiration. Unfortunately, it works for multipart/form-data server-side handling, when I'm searching for a multipart/mixed client side handling of a response. In addition, it does not yield the headers specific to each data chunk from the response, and I need those headers.

To be more specific, I'm buiding with the excellent "requests" lib and Python 2.7 (sorry, I can't go to Python 3.x at the moment) a client library for the documents database MarkLogic 8 that provides some APIs with multipart/mixed responses like this one:

http://docs.marklogic.com/REST/POST/v1/eval

In other words I need something that may be used like this :

response = requests.post(some_uri, params=some_params, stream=True)
if response.headers['content-type'].startswith('multipart/mixed'):
    boundary = parse_boundary(response.headers['content-type'])

    generator = iter_multipart_response(response, boundary)
    for part_headers, part_body in generator:
        # I'm consuming parsed headers and bodies from response
        # In my application code

Cheers
-- 
Gilles Lenfant

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web