librelist archives

« back to archive

Show full http request and response on console.

Show full http request and response on console.

From:
Juan José Denis Corrales
Date:
2015-03-14 @ 18:41
Hello:
I need a more verbose logging to console. Can you help me? I will explain
myself with an example:

Using the minimal application described in quickstart I get the following:

    $ python prueba_flask.py

    * Running on http://127.0.0.1:5000/

    127.0.0.1 - - [14/Mar/2015 19:02:57] "GET / HTTP/1.1" 200 -
    127.0.0.1 - - [14/Mar/2015 19:02:57] "GET / HTTP/1.1" 200 -

But I'm a beginner, and I would like to see the full http request,
something like curl does, something like this:

    $ python prueba_flask.py

    * Running on http://127.0.0.1:5000/

    127.0.0.1 - - [14/Mar/2015 19:02:57]

        > GET / HTTP/1.1
        > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0
           OpenSSL/0.9.8| zlib/1.2.5
        > Host: 127.0.0.1:5000
        > Accept: */*

        < HTTP/1.0 200 OK
        < Content-Type: text/html; charset=utf-8
        < Content-Length: 12
        < Server: Werkzeug/0.9.6 Python/2.7.9
        < Date: Sat, 14 Mar 2015 18:24:44 GMT

How could I configure flask so I can get this behavior?

Thank you very much!!!!!

Re: [flask] Show full http request and response on console.

From:
Winston Kouch
Date:
2015-03-14 @ 19:46
Hi,

This is not the best way to do this I think.. but until someone gives you a
better answer you can use to get what you want. It is out that is similar
to the curl request format.

Example code

app.py:

from flask import Flask, Response
app = Flask(__name__)

@app.route('/')
def index():
    resp = Response('/')
    print (resp.__dict__)
    return 'resp'

if __name__ == '__main__':
    app.debug = True
    app.run()


Example output:

{'_on_close': [], 'response': ['/'], 'headers': Headers([('Content-Type',
u'text/html; charset=utf-8'), ('Content-Length', u'1')]), '_status_code':
200, '_status': '200 OK', 'direct_passthrough': False}
127.0.0.1 - - [14/Mar/2015 15:43:13] "GET / HTTP/1.1" 200 -


Hope this helps!!


Winston Kouch


On Sat, Mar 14, 2015 at 2:41 PM, Juan José Denis Corrales <jjdenis@gmail.com
> wrote:

> Hello:
> I need a more verbose logging to console. Can you help me? I will explain
> myself with an example:
>
> Using the minimal application described in quickstart I get the following:
>
>     $ python prueba_flask.py
>
>     * Running on http://127.0.0.1:5000/
>
>     127.0.0.1 - - [14/Mar/2015 19:02:57] "GET / HTTP/1.1" 200 -
>     127.0.0.1 - - [14/Mar/2015 19:02:57] "GET / HTTP/1.1" 200 -
>
> But I'm a beginner, and I would like to see the full http request,
> something like curl does, something like this:
>
>     $ python prueba_flask.py
>
>     * Running on http://127.0.0.1:5000/< /div>
>
>     127.0.0.1 - - [14/Mar/2015 19:02:57]
>
>         > GET / HTTP/1.1
>         > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0
>            OpenSSL/0.9.8| zlib/1.2.5
>         > Host: 127.0.0.1:5000
>         > Accept: */*
>
>         < HTTP/1.0 200 OK
>         < Content-Type: text/html; charset=utf-8
>         < Content-Length: 12
>         < Server: Werkzeug/0.9.6 Python/2.7.9
>         < Date: Sat, 14 Mar 2015 18:24:44 GMT
>
> How could I configure flask so I can get this behavior?
>
> Thank you very much!!!!!
>
>

Re: [flask] Show full http request and response on console.

From:
Juan José Denis Corrales
Date:
2015-03-14 @ 19:57
Thank you very much for your response, but I wanted it for any page, not
just index.html, because what I am trying to debug is an Eve app, that
exposes a Rest API.

I am documenting my efforts here:
https://github.com/jjdenis/eve-restangular-demo

Thank you !!!!


2015-03-14 20:46 GMT+01:00 Winston Kouch <kwinston05@gmail.com>:

> Hi,
>
> This is not the best way to do this I think.. but until someone gives you
> a better answer you can use to get what you want. It is out that is similar
> to the curl request format.
>
> Example code
>
> app.py:
>
> from flask import Flask, Response
> app = Flask(__name__)
>
> @app.route('/')
> def index():
>     resp = Response('/')
>     print (resp.__dict__)
>     return 'resp'
>
> if __name__ == '__main__':
>     app.debug = True
>     app.run()
>
>
> Example output:
>
> {'_on_close': [], 'response': ['/'], 'headers': Headers([('Content-Type',
> u'text/html; charset=utf-8'), ('Content-Length', u'1')]), '_status_co de':
> 200, '_status': '200 OK', 'direct_passthrough': False}
> 127.0.0.1 - - [14/Mar/2015 15:43:13] "GET / HTTP/1.1" 200 -
>
>
> Hope this helps!!
>
>
> Winston Kouch
>
>
> On Sat, Mar 14, 2015 at 2:41 PM, Juan José Denis Corrales <
> jjdenis@gmail.com> wrote:
>
>> Hello:
>> I need a more verbose logging to console. Can you help me? I will
>> explain myself with an example:
>>
>> Using the minimal application described in quickstart I get the following:
>>
>>     $ python prueba_flask.py
>>
>>     * Running on http://127.0.0.1:5000/
>>
>>     127.0.0.1 - - [14/Mar/2015 19:02:57] "GET / HTTP/1.1" 200 -
>>     127.0.0.1 - - [14/Mar/2015 19:02:57] "GET / HTTP/1.1" 200 -
>>
>> But I'm a beginner, and I would like to see the full http request,
>> something like curl does, something like this:
>>
>>     $ python prueba_flask.py
>>
>>     * Running on http://127.0.0.1:5000/< /div>
>>
>>     127.0.0.1 - - [14/Mar/2015 19:02:57]
>>
>>         > GET / HTTP/1.1
>>         > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0)
>> libcurl/7.24.0
>>            OpenSSL/0.9.8| zlib/1.2.5
>>         > Host: 127.0.0.1:5000
>>         > Accept: */*
>>
>>         < HTTP/1.0 200 OK
>>         < Content-Type: text/html; charset=utf-8
>>         < Content-Length: 12
>>         < Server: Werkzeug/0.9.6 Python/2.7.9
>>         < Date: Sat, 14 Mar 2015 18:24:44 GMT
>>
>> How could I configure flask so I can get this behavior?
>>
>> Thank you very much!!!!!
>>
>>
>

Re: [flask] Show full http request and response on console.

From:
Juan José Denis Corrales
Date:
2015-03-15 @ 07:44
Hi again, to clarify matters more:

I'd like to see the logging even when the response is a 4XX Client error,
or a 5XX Server error.

Juan José Denis Corrales

2015-03-14 20:46 GMT+01:00 Winston Kouch <kwinston05@gmail.com>:

> Hi,
>
> This is not the best way to do this I think.. but until someone gives you
> a better answer you can use to get what you want. It is out that is similar
> to the curl request format.
>
> Example code
>
> app.py:
>
> from flask import Flask, Response
> app = Flask(__name__)
>
> @app.route('/')
> def index():
>     resp = Response('/')
>     print (resp.__dict__)
>     return 'resp'
>
> if __name__ == '__main__':
>     app.debug = True
>     app.run()
>
>
> Example output:
>
> {'_on_close': [], 'response': ['/'], 'headers': Headers([('Content-Type',
> u'text/html; charset=utf-8'), ('Content-Length', u'1')]), '_status_co de':
> 200, '_status': '200 OK', 'direct_passthrough': False}
> 127.0.0.1 - - [14/Mar/2015 15:43:13] "GET / HTTP/1.1" 200 -
>
>
> Hope this helps!!
>
>
> Winston Kouch
>
>
> On Sat, Mar 14, 2015 at 2:41 PM, Juan José Denis Corrales <
> jjdenis@gmail.com> wrote:
>
>> Hello:
>> I need a more verbose logging to console. Can you help me? I will
>> explain myself with an example:
>>
>> Using the minimal application described in quickstart I get the following:
>>
>>     $ python prueba_flask.py
>>
>>     * Running on http://127.0.0.1:5000/
>>
>>     127.0.0.1 - - [14/Mar/2015 19:02:57] "GET / HTTP/1.1" 200 -
>>     127.0.0.1 - - [14/Mar/2015 19:02:57] "GET / HTTP/1.1" 200 -
>>
>> But I'm a beginner, and I would like to see the full http request,
>> something like curl does, something like this:
>>
>>     $ python prueba_flask.py
>>
>>     * Running on http://127.0.0.1:5000/< /div>
>>
>>     127.0.0.1 - - [14/Mar/2015 19:02:57]
>>
>>         > GET / HTTP/1.1
>>         > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0)
>> libcurl/7.24.0
>>            OpenSSL/0.9.8| zlib/1.2.5
>>         > Host: 127.0.0.1:5000
>>         > Accept: */*
>>
>>         < HTTP/1.0 200 OK
>>         < Content-Type: text/html; charset=utf-8
>>         < Content-Length: 12
>>         < Server: Werkzeug/0.9.6 Python/2.7.9
>>         < Date: Sat, 14 Mar 2015 18:24:44 GMT
>>
>> How could I configure flask so I can get this behavior?
>>
>> Thank you very much!!!!!
>>
>>
>

Re: [flask] Show full http request and response on console.

From:
David Nieder
Date:
2015-03-15 @ 13:37
On 14.03.2015 19:41, Juan José Denis Corrales wrote:
> Hello:
> I need a more verbose logging to console. Can you help me? I will explain
> myself with an example:
>
> Using the minimal application described in quickstart I get the following:
>
>      $ python prueba_flask.py
>
>      * Running on http://127.0.0.1:5000/
>
>      127.0.0.1 - - [14/Mar/2015 19:02:57] "GET / HTTP/1.1" 200 -
>      127.0.0.1 - - [14/Mar/2015 19:02:57] "GET / HTTP/1.1" 200 -
>
> But I'm a beginner, and I would like to see the full http request,
> something like curl does, something like this:
>
>      $ python prueba_flask.py
>
>      * Running on http://127.0.0.1:5000/
>
>      127.0.0.1 - - [14/Mar/2015 19:02:57]
>
>          > GET / HTTP/1.1
>          > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0
>             OpenSSL/0.9.8| zlib/1.2.5
>          > Host: 127.0.0.1:5000
>          > Accept: */*
>
>          < HTTP/1.0 200 OK
>          < Content-Type: text/html; charset=utf-8
>          < Content-Length: 12
>          < Server: Werkzeug/0.9.6 Python/2.7.9
>          < Date: Sat, 14 Mar 2015 18:24:44 GMT
>
> How could I configure flask so I can get this behavior?
>
> Thank you very much!!!!!
>

Hello!
A guick and dirty solution could be something like:

@app.before_request
def before():
     print '> %s %s' %(request.method, request.url)
     for k,v in request.headers:
         print '> %s: %s' %(k,v)
     print

@app.after_request
def after(response):
     print '< %s' %response.status
     for k,v in response.headers:
         print '< %s: %s' %(k,v)
     return response

Have a nice one,
David

Re: [flask] Show full http request and response on console.

From:
Juan José Denis Corrales
Date:
2015-03-15 @ 15:07
That's what I needed.

Thanks a lot!

2015-03-15 14:37 GMT+01:00 David Nieder <davidnieder@gmx.de>:

> On 14.03.2015 19:41, Juan José Denis Corrales wrote:
> > Hello:
> > I need a more verbose logging to console. Can you help me? I will explain
> > myself with an example:
> >
> > Using the minimal application described in quickstart I get the
> following:
> >
> >      $ python prueba_flask.py
> >
> >      * Running on http://127.0.0.1:5000/
> >
> >      127.0.0.1 - - [14/Mar/2015 19:02:57] "GET / HTTP/1.1" 200 -
> >      127.0.0.1 - - [14/Mar/2015 19:02:57] "GET / HTTP/1.1" 200 -
> >
> > But I'm a beginner, and I would like to see the full http request,
> > something like curl does, something like this:
> >
> >      $ python prueba_flask.py
> >
> >      * Running on http://127.0.0.1:5000/
> >
> >      127.0.0.1 - - [14/Mar/2015 19:02:57]
> >
> >          > GET / HTTP/1.1
> >          > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0)
> libcurl/7.24.0
> >             OpenSSL/0.9.8| zlib/1.2.5
> >          > Host: 127.0.0.1:5000
> >          > Accept: */*
> >
> >          < HTTP/1.0 200 OK
> >          < Content-Type: text/html; charset=utf-8
> >          < Content-Length: 12
> >          < Server: Werkzeug/0.9.6 Python/2.7.9
> >          < Date: Sat, 14 Mar 2015 18:24:44 GMT
> >
> > How could I configure flask so I can get this behavior?
> >
> > Thank you very much!!!!!
> >
>
> Hello!
> A guick and dirty solution could be something like:
>
> @app.before_request
> def before():
>      print '> %s %s' %(request.method, request.url)
>      for k,v in request.headers:
>          print '> %s: %s' %(k,v)
>      print
>
> @app.after_request
> def after(response):
>      print '< %s' %response.status
>      for k,v in response.headers:
>          print '< %s: %s' %(k,v)
>      return response
>
> Have a nice one,
> David
>