[Tutor] getting binary file from website with custom header

Alex Hall mehgcap at gmail.com
Sat Jan 29 20:39:38 CET 2011


On 1/29/11, Steven D'Aprano <steve at pearwood.info> wrote:
> Alex Hall wrote:
>
>> Sorry. http://api.bookshare.org.
>
> Hmmm, I get:
>
> 403 Developer Inactive
>
> so that's no help to me. However, I did find this:
>
> http://developer.bookshare.org/docs/Home/
>
> [quote]
> For user authenticated services, the user's username will be passed in
> via the for parameter in the endpoint path.  The password should be
> derived as (Java syntax): md5sum(userPassword), where userPassword is
> the password of the user on whose behalf the service is being requested.
> [end quote]
>
> Unfortunately, that might be Java syntax (and also C syntax, Python
> syntax, Fortran syntax, and about a million other languages...) but
> there's no clue as to what the result should look like. Do they want an
> numeric string? In decimal or some other base? A string?
I posted on a forum just in case (just found the forums), but it looks
like they wanted urllib.quote(hex digest of password).
>
>>> It may matter. urllib has some problems with https.
>> Wonderful... Time to find another package?
>
> Not necessarily. Don't jump to conclusions. "Some problems" doesn't
> necessarily mean that you're seeing them.
>
>
>>> 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!
> But having said that...
>
>> The url should be right. I am now at an error 500 instead of 403,
>> which is rather strange. I know 500=internal server error, but as far
>> as I know the api is not down.
>
> Sounds to me that whatever their server is using to authenticate is broken.
>
>
>
> --
> Steven
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap


More information about the Tutor mailing list