Python HTTP digest authentication woes...

ravelox nixdoc at ravelox.co-dot-uk.no-spam.invalid
Mon Aug 8 07:54:03 CEST 2005


I hacked this a little bit and it seems to do the trick.


import urllib2

theurl =
"192.168.0.25/TiVoConnect?Container=%2FNowPlaying&Command=QueryContainer&Recurse=Yes"
print theurl

protocol = 'https://'
username = 'tivo'
password = '1111111111'

authhandler = urllib2.HTTPDigestAuthHandler()
authhandler.add_password("TiVo DVR",
"192.168.0.25", username, password)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
try:
        pagehandle = urllib2.urlopen(protocol + theurl)
        print pagehandle.readlines()
except IOError, e:
        if hasattr(e, 'code'):
                if e.code != 401:
                        print 'We got another error'
                        print e.code
                else:
                        print "Error 401"
                        print e.headers
                        print e.headers['www-authenticate']


Cheers

Dave




More information about the Python-list mailing list