This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bwmcadams
Recipients bwmcadams
Date 2008-02-28.18:26:32
SpamBayes Score 0.434845
Marked as misclassified No
Message-id <>
URLLIB2 seems to have issues attempting to digest authenticate against a
Windows-based IIS 6.x server.  The IIS server requests MD5-sess support,
and URLLIB2 throws an exception that ... far from explains this:

Traceback (most recent call last):
  File "/usr/lib64/python2.5/", line 95, in run_module
    filename, loader, alter_sys)
  File "/usr/lib64/python2.5/", line 52, in _run_module_code
    mod_name, mod_fname, mod_loader)
  File "/usr/lib64/python2.5/", line 32, in _run_code
    exec code in run_globals
  File "/srv/pubPal/test/", line 16, in <module>
  File "/usr/lib64/python2.5/", line 380, in open
    response = meth(req, response)
  File "/usr/lib64/python2.5/", line 491, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib64/python2.5/", line 412, in error
    result = self._call_chain(*args)
  File "/usr/lib64/python2.5/", line 353, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.5/", line 992, in http_error_401
    host, req, headers)
  File "/usr/lib64/python2.5/", line 884, in http_error_auth_reqed
    return self.retry_http_digest_auth(req, authreq)
  File "/usr/lib64/python2.5/", line 889, in
    auth = self.get_authorization(req, chal)
  File "/usr/lib64/python2.5/", line 920, in get_authorization
    H, KD = self.get_algorithm_impls(algorithm)
  File "/usr/lib64/python2.5/", line 972, in get_algorithm_impls
    return H, KD
UnboundLocalError: local variable 'H' referenced before assignment

The offending code is line 972:

    def get_algorithm_impls(self, algorithm):
        # lambdas assume digest modules are imported at the top level
        if algorithm == 'MD5':
            H = lambda x: hashlib.md5(x).hexdigest()
        elif algorithm == 'SHA':
            H = lambda x: hashlib.sha1(x).hexdigest()
        # XXX MD5-sess
        KD = lambda s, d: H("%s:%s" % (s, d))
        return H, KD

I'm not sure what's meant by the # XXX MD5-sess comment there... But
what ends up happening is that MD5-sess matches neither the if or the
elif, and when return attempts to return, H is undefined.

This could be easily patched, but support for MD5-sess would be great as

In my estimation, at the least, urllib2 shouldn't crap out in such an
obscure way when encountering an unsupported algorithm.

I'd suggest changing line 970 (The # XXX MD5-sess line) to:

 raise Exception, "Unsupported Digest Authentication Algorithm '%s'" %
Date User Action Args
2008-02-28 18:26:34bwmcadamssetspambayes_score: 0.434845 -> 0.434845
recipients: + bwmcadams
2008-02-28 18:26:34bwmcadamssetspambayes_score: 0.434845 -> 0.434845
messageid: <>
2008-02-28 18:26:33bwmcadamslinkissue2202 messages
2008-02-28 18:26:32bwmcadamscreate