As of a couple of days ago I wa开发者_如何学编程s able to access my google spreadsheets from an app (in app engine), but today it is broken.
Namely, I could
name= "name of my spreadsheet"
self.client = gdata.spreadsheet.text_db.DatabaseClient()
self.client.GetDatabases(name=name)
and it worked. In fact, that still works when I run with the dev_appserver
But, if crashes when on the app engine. It says it can't parse the XML.
I added some prints to the gdata code and found out that it could not parse it because what it thought was XML was actually just the HTML of the login page.
What is now happening is that the python gdata library does a ('eleanor' is the spreadsheet name)
GET /feeds/documents/private/full?title=eleanor
and gets back
<HTML>
<HEAD>
<TITLE>Moved Temporarily</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Moved Temporarily</H1>
The document has moved <A HREF="https://www.google.com/accounts/
ServiceLogin?
service=writely&passive=true&nui=1&continue=http%3A%2F
%2Fdocs.google.com%2Ffeeds%2Fdocuments%2Fprivate%2Ffull%3Ftitle
%3Deleanor&followup=http%3A%2F%2Fdocs.google.com%2Ffeeds
%2Fdocuments%2Fprivate%2Ffull%3Ftitle%3Deleanor">here</A>.
</BODY>
</HTML>
but, the same GET on the when running locally on the dev_appserver.py returns the proper XML:
<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/
2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'
xmlns:docs='http://schemas.google.com/docs/2007' xmlns:batch='http://
schemas.google.com/gdata/batch' xmlns:gd='http://schemas.google.com/g/
2005'><id>http://docs.google.com/feeds/documents/private/full</
id><updated>2009-10-29T19:14:07.401Z</updated><category scheme=......
I double checked and, yes, my app is authorized to access google docs.
So, what's up with the "Moved Temporarily". Is that a transient problem at the googleplex, or is it some authentication problem?
Docs is redirecting you to the login page. You need to authenticate before attempting to fetch the spreadsheet. I'm not sure why it's not requiring you to authenticate on the dev server, though.
You probably have to unrestricted access to the spreadsheet. You don't have it shared so everyone can view it.
Can read about sharing here.
Ninja Edit:
I didn't realize you could access the spreadsheet directly from app-engine. Google also has some info on how to authenticate with Google Spreadsheets over here. Have you checked the version of your local environment? Maybe this is something new that your dev environment hasn't picked up yet?
Check my answer on http://blog.forret.com/2011/07/google-docs-infamous-moved-temporarily-error-fixed/
If you add "&ndplr=1" to the link, Google will not try to redirect for authentication.
Ok, it now works. The Google has healed itself.
To be clear, I did not change anything in my code and the problem went away. It must have been a transient error at Google.
I'm hoping these type of errors will be really rare, as they bring my whole web app down.
精彩评论