On Tue, Jul 14, 2009 at 8:03 PM, epb<[email protected]> wrote: > > Hi, > > I am trying to make my Python program talk to a web service hosted on > app engine. I am using the appengine-rest-server and authentication > using a Google account is required on the server. The idea is that the > user specifies his username/password in the client application, and > then the client app. will talk to app engine server via webservices.
You may want to look at appengine_rpc.py, in the SDK google.appengine.tools package. It is designed specifically for this. > > I found this post: > http://groups.google.com/group/google-appengine/browse_thread/thread/3bd69f0aa72d4bcb/8f872170bd996ad6?lnk=gst&q=webservice+authentication#8f872170bd996ad6. > The guy who replied proposes the use of Authentication for Installed > Apps, but also mentions that the GAE service should be "ah", which it > is not according to > http://code.google.com/apis/base/faq_gdata.html#clientlogin > (in fact, GAE is not even listed there). What is the service name for > GAE (if it exists) and can I access the GAE application in this way? The service is, as mentioned, 'ah', and yes, you can authenticate using this method. > Given the service name I should be able to talk to the server like > this: > > import urllib, urllib2 > > # user-data > data = urllib.urlencode({'accountType' : 'GOOGLE', 'Email' : > '[email protected]', 'Passwd': 'xxx', 'service': 'someservice' , > 'source' : 'Me-MyApp-1.0'}) > > # do the log-in > f = urllib.urlopen('https://www.google.com/accounts/ClientLogin',data) > > # read ClientLogin token (ugly) > line = f.readline() > token = '' > while line: > if line.startswith('Auth'): > token = line[5:] > line = g.readline() The returned body is urlencoded, so you can use the built in functionality for this. > > # if we got token, login was completed > if token: > # URL to a Model called testmodel (via appengine-rest-server) > url = 'http://myappengineapp.appspot.com/rest/testmodel' > # add Authorization header with token > headers = {'Authorization': 'GoogleLogin auth='+token} > handler = urllib2.HTTPHandler() > opener = urllib2.build_opener(handler) > req = urllib2.Request(url, headers=headers) > f = opener.open(req) App Engine apps do not accept authorization headers - instead, you need to make a request to a special URL with the token to get a user cookie back. See appengine_rpc.py for details. -Nick Johnson > > # Do something with response.... > > # close "files" > f.close() > g.close() > > Correct? In fact, I am able to login, but somehow I can't use the > token to access the GAE app.. > > > > -- Nick Johnson, App Engine Developer Programs Engineer Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration Number: 368047 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---
