[Tutor] getting binary file from website with custom header
Steven D'Aprano
steve at pearwood.info
Sat Jan 29 23:21:43 CET 2011
Alex Hall wrote:
>>>> What makes you think you should use the *hex* digest of the password,
>>>> rather than some other format?
>>> Honestly, it seemed the logical choice, and the api docs to not say
>>> anything except to md5Sum() the password. I have tried it with and
>>> without the hexdigest() and nothing changed. I will look to see what
>>> else hashlib provides.
>> Try urllib.quote(hashlib.md5(password).digest()) and see if that helps.
> Almost! It did not work that way, but doing the exact same thing with
> hexdigest did it. Looks like I had to quote(md5(password).hexdigest())
> and that is all it wanted. The default user-agent even works. Thanks!
That's remarkable. By definition, the hexdigest should be nothing but
hex digits 0...9a...f. There shouldn't be anything there that needs
quoting, or changes after quoting:
>>> hashlib.md5("hello world").hexdigest()
'5eb63bbbe01eeed093cb22bb8f5acdc3'
>>> urllib.quote(hashlib.md5("hello world").hexdigest())
'5eb63bbbe01eeed093cb22bb8f5acdc3'
I am amazed that your password works with quoting but not without it. It
shouldn't make any difference.
--
Steven
More information about the Tutor
mailing list