The example provided in docs for Google App Engine remote_api did not quit work for me right away. Here are some modifications that will make it work.
First of all (thanks to the following post) use instead the following code (for OSX) for appengine_console.py:
#!/usr/bin/python
#http://allen.hutchison.org/2009/03/appengine-remoteapi-example-on-os-x.html
import code
import getpass
import os
import sys
DIR_PATH = "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine"
EXTRA_PATHS = [
DIR_PATH,
os.path.join(DIR_PATH, 'lib', 'yaml', 'lib'),
]
sys.path = EXTRA_PATHS + sys.path
from google.appengine.ext.remote_api import remote_api_stub
from google.appengine.ext import db
def auth_func():
return raw_input('Username:'), getpass.getpass('Password:')
if len(sys.argv) < 2:
print "Usage: %s app_id [host]" % (sys.argv[0],)
app_id = sys.argv[1]
if len(sys.argv) > 2:
host = sys.argv[2]
else:
host = '%s.appspot.com' % app_id
remote_api_stub.ConfigureRemoteDatastore(app_id, '/remote_api', auth_func, host)
code.interact('App Engine interactive console for %s' % (app_id,), None, locals())
Don't forget to comment out (or change from *) the helloworld.py in app.yaml
handlers:
#- url: /.*
# script: helloworld.py
- url: /remote_api
script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
login: admin
Otherwise you will get the following error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/google_appengine/google/appengine/ext/db/__init__.py", line 1336, in __iter__
return self.run()
File "/Applications/google_appengine/google/appengine/ext/db/__init__.py", line 1742, in run
query_run = self._proto_query.Run(*self._args, **self._kwds)
File "/Applications/google_appengine/google/appengine/ext/gql/__init__.py", line 657, in Run
res = bind_results.Get(self.__limit, offset)
File "/Applications/google_appengine/google/appengine/api/datastore.py", line 942, in Get
return self._Run(limit, offset)._Next(limit)
File "/Applications/google_appengine/google/appengine/api/datastore.py", line 1536, in _Next
apiproxy_stub_map.MakeSyncCall('datastore_v3', 'Next', req, result)
File "/Applications/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 68, in MakeSyncCall
apiproxy.MakeSyncCall(service, call, request, response)
File "/Applications/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 240, in MakeSyncCall
stub.MakeSyncCall(service, call, request, response)
File "/Applications/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 181, in MakeSyncCall
handler(request, response)
File "/Applications/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 219, in _Dynamic_Next
'remote_datastore', 'RunQuery', request, query_result)
File "/Applications/google_appengine/google/appengine/ext/remote_api/remote_api_stub.py", line 147, in MakeSyncCall
request_pb.Encode()))
File "/Applications/google_appengine/google/appengine/tools/appengine_rpc.py", line 344, in Send
f = self.opener.open(req)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 389, in open
response = meth(req, response)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 502, in http_response
'http', request, response, code, msg, hdrs)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 427, in error
return self._call_chain(*args)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 361, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 510, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 404: Not Found
The guestbook example gave the following error:
>>> import helloworld
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/neil/Documents/workspace/helloworld/src/helloworld.py", line 5, in <module>
from google.appengine.ext import webapp
File "/Applications/google_appengine/google/appengine/ext/webapp/__init__.py", line 68, in <module>
import webob
ImportError: No module named webob
Instead of using somewhat convoluted example provided by the docs
Just copy and paste the following sections separated by bold comments (make sure to paste them separately):
from google.appengine.ext import db
class Greeting(db.Model):
author = db.UserProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
# Now make sure to hit enter couple of times to get out of ident mode
q = db.GqlQuery("SELECT * FROM Greeting ORDER BY date DESC LIMIT 10")
results = q.fetch(5)
# Enter the username and password
for r in results:
print r.content