getting debug from urllib2

Discussion in 'Python' started by Ben Edwards, Jul 31, 2006.

  1. Ben Edwards

    Ben Edwards Guest

    Have been experimenting with HTTP stuff in python 2.4 and am having a
    problem getting debug info. If I use utllib.utlopen I get debug but if I
    user utllib2 I do not. Below is the probram and the output I am
    getting.

    Any insight?
    Ben

    * Code *

    import urllib, urllib2, httplib

    url = 'http://www.mozillazine.org/atom.xml'
    httplib.HTTPConnection.debuglevel = 1

    print "urllib"

    data = urllib.urlopen(url);

    print "urllib2"

    request = urllib2.Request(url)
    opener = urllib2.build_opener()
    feeddata = opener.open(request).read()

    print "End\n"

    * Output *

    urllib
    connect: (www.mozillazine.org, 80)
    send: 'GET /atom.xml HTTP/1.0\r\nHost: www.mozillazine.org\r
    \nUser-agent: Python-urllib/1.16\r\n\r\n'
    reply: 'HTTP/1.0 200 OK\r\n'
    header: Date: Mon, 31 Jul 2006 13:43:11 GMT
    header: Server: Apache/2.0.55 (Gentoo) PHP/4.4.0-pl1-gentoo
    header: Last-Modified: Thu, 27 Jul 2006 18:05:52 GMT
    header: ETag: "20a1b4-6bcf-be12000"
    header: Accept-Ranges: bytes
    header: Content-Length: 27599
    header: Content-Type: application/xml
    header: Age: 5
    header: X-Cache: HIT from mz5.mz.osuosl.org
    header: X-Cache-Lookup: HIT from mz5.mz.osuosl.org:80
    header: Connection: close
    urllib2
    End
    Ben Edwards, Jul 31, 2006
    #1
    1. Advertising

  2. Ben Edwards

    Peter Otten Guest

    Ben Edwards wrote:

    > Have been experimenting with HTTP stuff in python 2.4 and am having a
    > problem getting debug info. If I use utllib.utlopen I get debug but if I
    > user utllib2 I do not. Below is the probram and the output I am
    > getting.
    >
    > Any insight?


    Use the source :)

    urllib2.build_opener() accepts prebuilt handlers:

    import urllib2

    url = 'http://www.mozillazine.org/atom.xml'

    request = urllib2.Request(url)
    opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1))
    feeddata = opener.open(request).read()

    Peter
    Peter Otten, Jul 31, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RonL
    Replies:
    0
    Views:
    735
  2. ringos75
    Replies:
    0
    Views:
    950
    ringos75
    Apr 14, 2005
  3. Josef Cihal
    Replies:
    0
    Views:
    738
    Josef Cihal
    Sep 5, 2005
  4. Replies:
    1
    Views:
    966
    Rene Pijlman
    Mar 10, 2006
  5. cgoldberg
    Replies:
    5
    Views:
    2,341
    cgoldberg
    Mar 3, 2009
Loading...

Share This Page