GAE + gdata-python-client

1,840 views
Skip to first unread message

wachaca

unread,
Apr 9, 2008, 7:26:47 PM4/9/08
to Google App Engine

Hello,

I downloaded gdata-python-client 1.0.12 in order to develop an
application which is to run on GAE which connects to google data
services (docs, etc).
I also downloaded python 2.5 (I'm a new to python, been using it for
36 hours)

The following code, which is GAE free runs from command line without
any problems. I was a happy newbie

import gdata.contacts.service
import gdata.service

class MainPage():

def get(self):
# Create a client class which will make HTTP requests with Google
Docs server.
client = gdata.contacts.service.ContactsService()
# Authenticate using your Google Docs email address and password.
client.ClientLogin('wach...@gmail.com', 'thisisnotmypassword')

# Query the server for an Atom feed containing a list of your
documents.
documents_feed = client.GetContactsFeed()
# Loop through the feed and extract each document entry.
for document_entry in documents_feed.entry:
# Display the title of the document on the command line.
print document_entry.title.text

def main():
sample = MainPage()
sample.get()

if __name__ == "__main__":
main()

But when I adapt this code to run over GAE I get nothing but errors:
import gdata.contacts.service
import gdata.service
import gdata.urlfetch

class MainPage():

def get(self):
# Create a client class which will make HTTP requests with Google
Docs server.
gdata.service.http_request_handler = gdata.urlfetch
client = gdata.contacts.service.ContactsService()
# Authenticate using your Google Docs email address and password.
client.ClientLogin('wach...@gmail.com', 'thisisnotmypassword')

# Query the server for an Atom feed containing a list of your
documents.
documents_feed = client.GetContactsFeed()
# Loop through the feed and extract each document entry.
for document_entry in documents_feed.entry:
# Display the title of the document on the command line.
print document_entry.title.text

def main():
sample = MainPage()
sample.get()

if __name__ == "__main__":
main()

C:\Python25\lib\gdata\__init__.py in ()
31 import cElementTree as ElementTree
32 except ImportError:
33 from elementtree import ElementTree
34 import atom
35
elementtree undefined, ElementTree undefined

<type 'exceptions.ImportError'>: No module named elementtree
args = ('No module named elementtree',)
message = 'No module named elementtree'

So I changed all the imports line in the libraries to
from xml.etree import ElementTree

And then this gave me:
<type 'exceptions.ImportError'>: No module named expat; use
SimpleXMLTreeBuilder instead
args = ('No module named expat; use SimpleXMLTreeBuilder
instead',)
message = 'No module named expat; use SimpleXMLTreeBuilder
instead'

Whats missing so that this runs on GAE?

Brett Morgan

unread,
Apr 9, 2008, 7:28:51 PM4/9/08
to google-a...@googlegroups.com
You can't open ports from within python. The only way you can get to
the outside world is via URLFetch.

http://code.google.com/appengine/docs/urlfetch/

Brett Morgan

unread,
Apr 9, 2008, 7:30:41 PM4/9/08
to google-a...@googlegroups.com
Oh, wait. Now that i have read the stack trace...

Have a geek back through the list looking for all the posts about the
missing XML parser functionality.

The python in GAE is basically missing pretty much all the C based
extensions. This is to make sure that the users are operating within a
safe sandbox and don't impact the environment in which they are
running.

On Thu, Apr 10, 2008 at 9:26 AM, wachaca <wach...@gmail.com> wrote:
>
>

wachaca

unread,
Apr 10, 2008, 2:30:06 AM4/10/08
to Google App Engine
According to this google blog,
http://googledataapis.blogspot.com/2008/04/release-hounds-support-for-app-engine.html

it should work by invoking the code:
gdata.service.http_request_handler = gdata.urlfetch

Since this code was designed for GAE, in theory it should work.
> >                                 client.ClientLogin('wachac...@gmail.com', 'thisisnotmypassword')
>
> >                                 # Query the server for an Atom feed containing a list of your
> >  documents.
> >                                 documents_feed = client.GetContactsFeed()
> >                                 # Loop through the feed and extract each document entry.
> >                                 for document_entry in documents_feed.entry:
> >                                   # Display the title of the document on the command line.
> >                                   print document_entry.title.text
>
> >                 def main():
> >                   sample = MainPage()
> >                   sample.get()
>
> >                 if __name__ == "__main__":
> >                   main()
>
> >  But when I adapt this code to run over GAE I get nothing but errors:
> >                 import gdata.contacts.service
> >                 import gdata.service
> >                 import gdata.urlfetch
>
> >                 class MainPage():
>
> >                   def get(self):
> >                                 # Create a client class which will make HTTP requests with Google
> >  Docs server.
> >                                 gdata.service.http_request_handler = gdata.urlfetch
> >                                 client = gdata.contacts.service.ContactsService()
> >                                 # Authenticate using your Google Docs email address and password.
> >                                 client.ClientLogin('wachac...@gmail.com', 'thisisnotmypassword')
> >  Whats missing so that this runs on GAE?- Hide quoted text -
>
> - Show quoted text -

Brett

unread,
Apr 10, 2008, 2:32:46 AM4/10/08
to Google App Engine


On Apr 9, 4:26 pm, wachaca <wachac...@gmail.com> wrote:
> Hello,
>
> I downloaded gdata-python-client 1.0.12 in order to develop an
> application which is to run on GAE which connects to google data
> services (docs, etc).
> I also downloaded python 2.5 (I'm a new to python, been using it for
> 36 hours)
>
> The following code, which is GAE free runs from command line without
> any problems. I was a happy newbie
>
> import gdata.contacts.service
> import gdata.service
>
> class MainPage():
>
> def get(self):
> # Create a client class which will make HTTP requests with Google
> Docs server.
> client = gdata.contacts.service.ContactsService()
> # Authenticate using your Google Docs email address and password.
> client.ClientLogin('wachac...@gmail.com', 'thisisnotmypassword')
>
> # Query the server for an Atom feed containing a list of your
> documents.
> documents_feed = client.GetContactsFeed()
> # Loop through the feed and extract each document entry.
> for document_entry in documents_feed.entry:
> # Display the title of the document on the command line.
> print document_entry.title.text
>
> def main():
> sample = MainPage()
> sample.get()
>
> if __name__ == "__main__":
> main()
>
> But when I adapt this code to run over GAE I get nothing but errors:
> import gdata.contacts.service
> import gdata.service
> import gdata.urlfetch
>
> class MainPage():
>
> def get(self):
> # Create a client class which will make HTTP requests with Google
> Docs server.
> gdata.service.http_request_handler = gdata.urlfetch
> client = gdata.contacts.service.ContactsService()
> # Authenticate using your Google Docs email address and password.
> client.ClientLogin('wachac...@gmail.com', 'thisisnotmypassword')
Ah I think I see the problem.

From the source:
(http://code.google.com/p/gdata-python-client/source/browse/trunk/src/
gdata/__init__.py)


import os
try:
from xml.etree import cElementTree as ElementTree
except ImportError:
try:
import cElementTree as ElementTree
except ImportError:
from elementtree import ElementTree

This is missing one more thing:

from xml.etree import ElementTree


That works on AppEngine. Try changing your gdata/__init__.py file to
match that, instead of cElementTree. I will file an issue against the
GData Python project.

Jeff S

unread,
Apr 10, 2008, 1:07:17 PM4/10/08
to Google App Engine
Hi Brett and wachaca,

Apologies, I had missed the import for the non-c version of
ElementTree throughout the gdata-python-client library. These imports
needed to be fixed in several places, which I have now done. Would you
mind checking out the latest changes from subversion? Once I get some
good feedback on this fix, I'll release a new download with the import
changes.

svn checkout http://gdata-python-client.googlecode.com/svn/trunk/
gdata-python-client-read-only

Thank you,

Jeff
> > args = ('No module namedelementtree',)

Jeff S

unread,
Apr 10, 2008, 6:18:43 PM4/10/08
to Google App Engine
There's a new download available with the fix for import statements.
Thank you again for mentioning this.

http://code.google.com/p/gdata-python-client/downloads/list

Happy coding,

Jeff

On Apr 10, 10:07 am, Jeff S <j...@google.com> wrote:
> Hi Brett and wachaca,
>
> Apologies, I had missed the import for the non-c version of
> ElementTree throughout the gdata-python-client library. These imports
> needed to be fixed in several places, which I have now done. Would you
> mind checking out the latest changes from subversion? Once I get some
> good feedback on this fix, I'll release a new download with the import
> changes.
>
> svn checkouthttp://gdata-python-client.googlecode.com/svn/trunk/

FreeAgent

unread,
Apr 11, 2008, 1:48:46 PM4/11/08
to Google App Engine
Hi Jeff,

Thanks for the prompt patch release!

I found the same error ("No module named elementtree"), then found the
solution on this thread by searching this group.

However, having got past that error I got another: "No module named
atom".

So I copied over the atom module to my project directory.

Then I got "No module named expat: use SimpleXMLTreeBuilder instead".

Maybe I'm doing something unsupported?

I've been trying to run the "Hello World" example on this page
(substituting my username & password for local testing):

http://code.google.com/support/bin/answer.py?answer=75582

Again, it runs just fine from the command-line, I get the error when I
try it with GAE (with Django, on Windows).

Thanks for your help!

Kevin.

Berco Beute

unread,
Apr 11, 2008, 4:20:56 PM4/11/08
to Google App Engine
That's from ElementTree, see:

http://effbot.python-hosting.com/file/elementtree/docs/pythondoc-elementtree.SimpleXMLTreeBuilder.html

'expat' uses C extensions so the atom module should use
SimpleXMLTreeBuilder to build a...well...XML tree.

hth
2B

gpfsmurf

unread,
Apr 13, 2008, 5:50:56 PM4/13/08
to Google App Engine
You can force ElementTree to use SimpleXMLTreeBuilder. Not sure if
it's the proper way to do it, but it works:

from xml.etree import ElementTree, SimpleXMLTreeBuilder
ElementTree.XMLTreeBuilder = SimpleXMLTreeBuilder.TreeBuilder


Sami

Robert

unread,
Apr 22, 2008, 3:02:50 AM4/22/08
to Google App Engine
I'm using python 2.5 and did not find the SimpleXMLTreeBuilder class
in my Python runtime, gdata API or appengine api.
My solution was to search for "python 2.5 SimpleXMLTreeBuilder" in
Google Code Search, download the module and copy it to my projects
source as I did before with the GData API modules.

After that the above mentioned Problems vanished. :-)

Sebastian Aviña

unread,
Jun 3, 2008, 6:40:28 AM6/3/08
to Google App Engine
anybody has managed to download raw doc contents from a gdoc?

On Apr 22, 2:02 am, Robert <rbausd...@googlemail.com> wrote:
> I'm using python 2.5 and did not find the SimpleXMLTreeBuilder class
> in my Python runtime, gdata API or appengine api.
> My solution was to search for "python 2.5 SimpleXMLTreeBuilder" inGoogleCode Search, download the module and copy it to my projects
Reply all
Reply to author
Forward
0 new messages