Python3: Is this a bug in urllib?

Justin Ezequiel justin.mailinglists at gmail.com
Tue Oct 26 04:59:28 EDT 2010


'''
C:\Documents and Settings\Administrator\Desktop>python wtf.py
301 Moved Permanently
b'<HTML><HEAD><meta http-equiv="content-type" content="text/
html;charset=utf-8">
\n<TITLE>301 Moved</TITLE></HEAD><BODY>\n<H1>301 Moved</H1>\nThe
document has mo
ved\n<A HREF="http://www.google.de/">here</A>.\r\n</BODY></HTML>\r\n'
foo 5.328 secs
301 Moved Permanently
bar 241.016 secs

C:\Documents and Settings\Administrator\Desktop>
'''
import http.client
import time

def foo():
    c = http.client.HTTPConnection('google.de')
    try:
        c.request('GET', '/')
        r = c.getresponse()
        try:
            print(r.status, r.reason)
            x = r.read()
        finally: r.close()
    finally: c.close()
    print(x)

def bar():
    c = http.client.HTTPConnection('google.de')
    try:
        c.request('GET', '/')
        r = c.getresponse()
        try:
            print(r.status, r.reason)
            x = r.fp.read()
        finally: r.fp.close()
    finally: c.close()

s = time.time()
foo()
e = time.time()
print('foo %.3f secs' % (e-s,))

s = time.time()
bar()
e = time.time()
print('bar %.3f secs' % (e-s,))




More information about the Python-list mailing list