Hi guys,
I'm really perplexed by this one. I added the urlfetch fix and the
run_on_appengine but am not sure if I did it write. Without the
urlfetch fix it says that the port is not defined.
I am using the following code in GAE i get a 404 not found error:
===========
<pre>Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/
Resources/GoogleAppEngine-default.bundle/Contents/Resources/
google_appengine/google/appengine/ext/webapp/__init__.py", line
500, in __call__
handler.post(*groups)
File "/Users/Dean/Sites/helloworld/helloworld.py", line
134, in post
a = validateUser(email,pwd)
File "/Users/Dean/Sites/helloworld/helloworld.py", line
95, in validateUser
feed = gd_client.GetListFeed(sKey,wKeyUser,query = qga)
File "/Users/Dean/Sites/helloworld/gdata/spreadsheet/
service.py", line 249, in GetListFeed
converter=gdata.spreadsheet.SpreadsheetsListFeedFromString)
File "/Users/Dean/Sites/helloworld/gdata/service.py", line
1019, in Get
'reason': server_response.reason, 'body': result_body}
RequestError: {'status': 404, 'body': '<HTML>\n<HEAD>
\n<TITLE>Not Found</TITLE>\n</HEAD>\n<BODY
BGCOLOR="#FFFFFF" TEXT="#000000">
\n<H1>Not Found</H1>\n<H2>Error 404</H2>\n</
BODY>\n</HTML>\n', 'reason': ''}
</pre>
===========
If I do the same thing in native python with the client library it
works.
any ideas? I've changed the usernames and passwords in the pasted
code.
============
import os
import cgi
import string
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
from google.appengine.ext import db
import wsgiref.handlers
try:
from xml.etree import ElementTree
except ImportError:
from elementtree import ElementTree
import gdata.service
import gdata.alt.appengine
import atom.service
import gdata.spreadsheet
import gdata.spreadsheet.service
import atom
import gdata.urlfetch
# Use urlfetch instead of httplib
gdata.service.http_request_handler = gdata.urlfetch
import settings
import hashlib
from random import choice
from base64 import b64decode, b64encode
#b64hash = "OJF6H4KdxFLgLu+oTDNFodCEfMA=";
sKey = '<somekey>';
wKeyUser = 'od6';
wKeyLogin = 'od4';
wKeyTut = 'od7';
wKeyTutList = 'od5';
def GenPasswd(length=8, chars=string.letters+string.digits):
return ''.join([choice(chars) for i in range(length)])
def utf16tobin(s):
return s.encode('hex')[4:].decode('hex')
def checkhash(hashval, unhashed):
b64salt = "123456789012345678901234"
binsalt = b64decode(b64salt)
password_string = unhashed.encode("utf16")
password_string = utf16tobin(password_string)
m1 = hashlib.sha1()
# Pass in salt
m1.update(binsalt + password_string)
# Pass in password
# B64 encode the binary digest
if b64encode(m1.digest()) == hashval:
return True
else:
return False
def GSheetService():
client = gdata.service.GDataService()
gdata.alt.appengine.run_on_appengine(client)
gd_client = gdata.spreadsheet.service.SpreadsheetsService
(sKey,wKeyUser);
gd_client.email = '[email protected]';
gd_client.password = '<mypassword>';
return gd_client;
def PrintFeed(feed):
retstr = ""
for i, entry in enumerate(feed.entry):
if isinstance(feed, gdata.spreadsheet.SpreadsheetsCellsFeed):
print '%s %s %s<br>' % (i, entry.title.text,
entry.content.text)
elif isinstance(feed, gdata.spreadsheet.SpreadsheetsListFeed):
for key in entry.custom:
retstr += ' %s: %s<br>' % (key,
entry.custom[key].text)
retstr += 'done<br>',
else:
retstr += '%s %s<br>' % (i, entry.title.text)
return retstr
def validateUser(email,pwd):
gd_client = GSheetService();
qga = gdata.spreadsheet.service.ListQuery();
qga.sq = "email==" + email;
qga.orderby = "column:lastname"
feed = gd_client.GetListFeed(sKey,wKeyUser,query = qga)
if len(feed.entry)==1:
#we have one entry now lets get the password hash to compare
and the
return checkhash(qga.entry[0].custom['password'].text,pwd)
class MainPage(webapp.RequestHandler):
def get(self):
template_values = {
'error': '',
}
path = os.path.join(os.path.dirname(__file__), 'login.html')
self.response.out.write(template.render(path, template_values))
class LoginPage(webapp.RequestHandler):
def post(self):
# Initialize a client to talk to Google Data API services.
email = str(self.request.POST['email'])
pwd = str(self.request.POST['pwd'])
if email == "" or pwd == "":
self.redirect('/')
else:
#try:
a = validateUser(email,pwd)
self.response.out.write(a);
#except:
# self.response.headers['Content-Type'] =
'text/plain'
# self.response.out.write('Error connecting to
data')
#else:
#if a==True:
# self.response.headers['Content-Type'] =
'text/plain'
# self.response.out.write('Hello, webapp World!')
#else:
# template_values = {
# 'error': 'invalid Login',
# }
# path = os.path.join(os.path.dirname(__file__),
'login.html')
# self.response.out.write(template.render(path,
template_values))
application = webapp.WSGIApplication(
[('/', MainPage),
('/login', LoginPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---