ClientCookie.read() failing on some servers

Patrick Bussi patrick.bussi at free.fr
Sun Apr 6 11:11:59 EDT 2003


Hello,

I'm calling for help to diagnose this fail of ClientCookie.py as an URL 
opener (just in in place of urllib2.ulropen()).

Here is my simple program :

-------snip-------
#! /usr/bin/env python
'''Simple test of urllib2 request with ClientCookie opener
   usage:
   $ python test.py www.python.org
'''
import sys
import ClientCookie, urllib2, urllib
from urllib2 import Request

def timeStamp():
    import time
    t=time.time()
    return t, time.ctime(t)

def test(h):
    '''h is the host name. Caution : no protection against mistakes
    '''
    req = urllib2.Request('http://'+h)
    req.add_header('Host',h)
    req.add_header('User-agent', 
'Mozilla/5.5.(X11;.U;.Linux.2.4;.en-US;.0.8).Gecko/20010409')
    req.add_header('Accept','*/*')
    req.add_header('Accept-Language','en')
    req.add_header('Accept-Encoding','gzip,deflate,compress,identity')
    req.add_header('Keep-Alive','300')
    req.add_header('Connection','keep-alive')

    print '\n'.join(['%s' %k for k in (req.get_full_url(), 
req.get_selector(), req.headers)])
    response=ClientCookie.urlopen(req)
    print '\n2\n', response.info()
    if response: print response.read()
    print '\n3\n', '%s -  Data for server %s was :\n%s' %(timeStamp()[1], 
req.get_host(), req.get_data())


if __name__ == '__main__':
    import os, sys
    print 'Linux', ''.join(['%s'*3 %os.uname()[2:]])
    print 'Python', sys.version
    try:
        print sys.argv[1]
    except:
        print __doc__, '\nPython interpreter is :', sys.version
        sys.exit('Bad news')
    test(sys.argv[1])

-------snap-------


-------snip-------


-------snap-------


-------snip-------


-------snap-------






More information about the Python-list mailing list