473,320 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

getting debug from urllib2

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

Jul 31 '06 #1
1 11099
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(debugleve l=1))
feeddata = opener.open(request).read()

Peter
Jul 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: O. Koch | last post by:
Until now, i know that ftplib doesn't support proxies and that i have to use urllib2. But i don't know how to use the urllib2 correct. I found some examples, but i don't understand them. Is...
4
by: bmiras | last post by:
I've got a problem using urllib2 to get a web page. I'm going through a proxy using user/password authentification and i'm trying to get a page asking for a HTTP authentification. And I'm using...
2
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line...
1
by: Ray Slakinski | last post by:
Hello, I have defined a function to set an opener for urllib2, this opener defines any proxy and http authentication that is required. If the proxy has authencation itself and requests an...
1
by: joemynz | last post by:
Help please with a URLError. Invoking a url that works in Firefox and IE results in a "urlerror 7, no address ..." in python. I need to debug why. Traceback is below. There's a redirect when the...
5
by: blair.bethwaite | last post by:
Hi Folks, I'm thinking about writing a script that can be run over a whole site and produce a report about broken links etc... I've been playing with the urllib2 and httplib modules as a...
0
by: Baptiste Lepilleur | last post by:
I activated httplib debug, and when trace are printed, a UnicodeError exception is thrown. I have already set sys.stdout to use utf-8 encoding (this removed the exception when *I* was printing...
1
by: Alessandro Fachin | last post by:
I write this simply code that should give me the access to private page with htaccess using a proxy, i don't known because it's wrong... import urllib,urllib2 #input url...
1
by: iBlaine | last post by:
I'm hoping someone here can answer my problem - I'm getting a 500 error when I run this code. What it should do is setup cookies, log in, then post a file to a form. The problem is it throws an...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.