Problem getting Auth in Python

15 views
Skip to first unread message

Gordon Fontenot

unread,
Oct 19, 2009, 4:47:02 PM10/19/09
to Remember The Milk API
I must not have posted this in the thread I thought I posted in,
because it shouldn't take a week for it to be moderated and approved.
So, take 2:

I am having problems getting auth through Python. I have been going
crazy with this. I have followed the documentation to the T, but
obviously, I'm missing something, and I can't figure out what it is.
Here is the code to get the auth url:

auth_url='http://www.rememberthemilk.com/services/auth/?'
the_sig = api_secret+'api_key'+api_key+'frob'+the_frob+'permswrite'
hashed_sig= createMD5(the_sig)
url=auth_url+'api_key='+api_key+'&perms=write&frob='+the_frob
+'&api_sig='+(str(hashed_sig))


The Frob is coming back ok, the URL looks right when I print it out,
everything looks fine. So what am I missing?

Gordon Fontenot

unread,
Oct 20, 2009, 11:28:27 AM10/20/09
to Remember The Milk API
In other words, the URL I am building looks like this:

rememberthemilk.com/services/auth/?api_key=<API_KEY
HERE>&perms=write&frob=<FROB HERE>&api_sig=<SIG HERE>

The sig (pre MD5) is buit like so:

<API SECRET>api_key<API KEY>frob<FROB>permswrite

I really don't understand why this isn't working.

Any help would really be appreciated.
Message has been deleted

Roopesh Sheth

unread,
Oct 20, 2009, 9:19:03 AM10/20/09
to remembert...@googlegroups.com
I don't know Python, but I can see in your url variable you're not putting the parameters in alphabetical order.  The frob parameter should be before the perms parameter.  Looks like you did it right in the_sig.

Eric Wendelin

unread,
Oct 21, 2009, 1:06:04 AM10/21/09
to Remember The Milk API
Gordon:

I just tested auth with the URL parameters NOT in alphabetical order
and it worked for me. Try it anyway and if it doesn't work I would
recommend taking these steps:

0. Double check your api_key using rtm.test.echo if you haven't.
1. Make certain you are parsing the frob out of the xml correctly.
2. Check your MD5 generation, including the encoding you're using
(should be UTF-8). I recommend comparing the MD5 you get from Python
to one you hand craft and run through a different tool, just to make
sure.
3. Remember that a frob is invalid after ONE use (including a
failure). If you, say, try to make any other call other than one to
the auth URL after getting a frob with your api_key, it will fail.
This tripped me up a bit, since I don't think it's documented. You
cannot reuse a frob.

I hope any one of those solves your problem. If not, keep posting
stuff and we'll keep answering.

BTW, Python rocks. ;)

-Eric

Gordon Fontenot

unread,
Oct 21, 2009, 8:03:04 AM10/21/09
to Remember The Milk API
@roopesh: I have tried both ways. Alphabetically and non
alphabetically. Neither has worked. The documentation, btw has the url
being constructed non alphabetically.


@Eric:
My api key should be fine. I call rtm.auth.getFrob immediatly before
this, with no error.

I have checked and tripple checked my parsing method for the frob.
It's exactly the same as in the xml response.

The md5 hash shouldnt be an issue either, since the sig works fine for
the rtm.auth.getFrob method, right? Or is one method pickier than
another?

Not reusing the frob. I am calling for a new one each call.

Thanks for the help, guys. This is driving me nuts.
-Gordon

Eric Wendelin

unread,
Oct 21, 2009, 1:27:06 PM10/21/09
to Remember The Milk API
Gordon:

It all looks right to me.

Tell you what: I know Python, so if you send me your code (or post to
github) I'll use my api_key etc. and see if I can find the problem.

No guarantees I'll find the fix, but an extra set of eyes always
helps.

-Eric Wendelin
http://github.com/emwendelin
emwendelin at gmail

Gordon Fontenot

unread,
Oct 22, 2009, 9:38:00 AM10/22/09
to Remember The Milk API
Thanks, Eric.

The code is on GitHub here: http://github.com/gfontenot/RTM_QSB

A few disclaimers: This is literally the first thing I have written in
Python. I am also not using the PyRTM API kit. I wanted to do this
as an exercise for myself, and therefore wanted to do it from
scratch. The kit also had far more advanced capabilities than I
needed, since this code is just intended for pushing a task up to
RTM. It's also probably over-commented. I have a bad habit of not
commenting my code AT ALL, so I decided to go in the other direction
on this one in order to get myself used to the idea of commenting my
own code. I also knew this would be open-sourced at some point, and I
figured it would help to be able to see what I was thinking.

With all that said, please be gentle.

- Gordon

On Oct 21, 1:27 pm, Eric Wendelin <emwende...@gmail.com> wrote:
> Gordon:
>
> It all looks right to me.
>
> Tell you what: I know Python, so if you send me your code (or post to
> github) I'll use my api_key etc. and see if I can find the problem.
>
> No guarantees I'll find the fix, but an extra set of eyes always
> helps.
>
> -Eric Wendelinhttp://github.com/emwendelin

Eric Wendelin

unread,
Oct 23, 2009, 2:45:18 PM10/23/09
to Remember The Milk API
Gordon:

Fixed. Updated code at http://github.com/emwendelin/RTM_QSB

The problem was the MD5 generation. You have to call hashlib.md5() for
every hash.
NOTE: I had to remove a lot of code that used Cocoa because it's not
available on Linux. You might consider using pickle to store auth
tokens.

Anyway, much respect for trying Python and good luck on the
project. :)

Eric Wendelin
http://eriwen.com
@eriwen

Gordon Fontenot

unread,
Oct 25, 2009, 6:51:19 PM10/25/09
to Remember The Milk API
Thank you SO much. It all works now.

PS, this code is ultimatly going to be a plugin for Google Quick
Search Box (mac only), which is why I am using the plist and cocoa
stuff. I'm not going to pull your code, but I have updated mine
accordingly.

I also didn't know that %s trick you were using. Is that a faster way
of plugging that stuff in, or is it just cleaner?

Again, Thanks so much. You really saved me on this.

- Gordon

On Oct 23, 2:45 pm, Eric Wendelin <emwende...@gmail.com> wrote:
> Gordon:
>
> Fixed. Updated code athttp://github.com/emwendelin/RTM_QSB
>
> The problem was the MD5 generation. You have to call hashlib.md5() for
> every hash.
> NOTE: I had to remove a lot of code that used Cocoa because it's not
> available on Linux. You might consider using pickle to store auth
> tokens.
>
> Anyway, much respect for trying Python and good luck on the
> project. :)
>
> Eric Wendelinhttp://eriwen.com

Eric Wendelin

unread,
Nov 2, 2009, 12:53:23 PM11/2/09
to Remember The Milk API
You're very welcome :)

I figured out why you had those libs. Just wanted to explain why I
removed so much code.

The %s (string template) thing is not faster, just cleaner IMHO.

Let me know if you have other questions and I'll take a look. :)

-Eric
Reply all
Reply to author
Forward
0 new messages