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


Groups > comp.lang.python > #94951

Re: Parsing multipart HTTP response

Newsgroups comp.lang.python
Date 2015-08-03 10:15 -0700
References <648c131d-6315-4f83-88f0-b87bf3b530a9@googlegroups.com> <mailman.1195.1438616367.3674.python-list@python.org>
Message-ID <85fe942e-5318-4343-aa23-04033b7d270c@googlegroups.com> (permalink)
Subject Re: Parsing multipart HTTP response
From Gilles Lenfant <gilles.lenfant@gmail.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

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

csiph-web