ok.  So I narrowed it down.  if I use gqa.sq = "email=="+email where
the email contains "@'" it doesn't like it.  But this is not good.
How do I encode it so that the query filter still works?  Ideas?


On Mar 25, 2:10 pm, Jeff S <[email protected]> wrote:
> Hi mrsixcount,
>
> I haven't reproduced this issue but I have a few suggestions which
> would help narrow down the problem.
>
> I noticed the following lines, which can now be removed because
> run_on_appengine does the same thing.
>
> import gdata.urlfetch
> # Use urlfetch instead of httplib
> gdata.service.http_request_handler = gdata.urlfetch
>
> Also, I would recommend changing GSheerService to do something more
> like this:
>
> def GSheetService():
>   # When you passed in sKey and wKeyUser
>   # those are used as email and password
>   gd_client = gdata.spreadsheet.service.SpreadsheetsService();
>   # run_on_appengine should be called on the
>   # client being used. Also since this is using
>   # ClientLogin, I recommend turning off auto
>   # token storage and marking this as
>   # "single_user_mode" as shown below.
>   # More details here:
>   #http://code.google.com/appengine/articles/gdata.htmland
>   #http://code.google.com/appengine/articles/more_google_data.html
>   gdata.alt.appengine.run_on_appengine(gd_client, store_tokens=False,
>       single_user_mode=True)
>   gd_client.email = '[email protected]';
>   gd_client.password = '<mypassword>';
>   # After setting the username and password,
>   # the auth token must be obtained by
>   # calling ProgrammaticLogin (or ClientLogin)
>   gd_client.ProgrammaticLogin()
>   return gd_client;
>
> Could you give this a try and let me know how it goes? If this doesn't
> resolve the issue, please share your new code and I'll try to
> reproduce. Thanks for being so thorough with sharing your code, this
> is very helpful.
>
> Happy coding,
>
> Jeff
>
> On Mar 24, 1:56 pm, mrsixcount <[email protected]> wrote:
>
> > 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 &quot;/Applications/GoogleAppEngineLauncher.app/Contents/
> > Resources/GoogleAppEngine-default.bundle/Contents/Resources/
> > google_appengine/google/appengine/ext/webapp/__init__.py&quot;, line
> > 500, in __call__
> >     handler.post(*groups)
> >   File &quot;/Users/Dean/Sites/helloworld/helloworld.py&quot;, line
> > 134, in post
> >     a = validateUser(email,pwd)
> >   File &quot;/Users/Dean/Sites/helloworld/helloworld.py&quot;, line
> > 95, in validateUser
> >     feed = gd_client.GetListFeed(sKey,wKeyUser,query = qga)
> >   File &quot;/Users/Dean/Sites/helloworld/gdata/spreadsheet/
> > service.py&quot;, line 249, in GetListFeed
> >     converter=gdata.spreadsheet.SpreadsheetsListFeedFromString)
> >   File &quot;/Users/Dean/Sites/helloworld/gdata/service.py&quot;, line
> > 1019, in Get
> >     'reason': server_response.reason, 'body': result_body}
> > RequestError: {'status': 404, 'body': '&lt;HTML&gt;\n&lt;HEAD&gt;
> > \n&lt;TITLE&gt;Not Found&lt;/TITLE&gt;\n&lt;/HEAD&gt;\n&lt;BODY
> > BGCOLOR=&quot;#FFFFFF&quot; TEXT=&quot;#000000&quot;&gt;
> > \n&lt;H1&gt;Not Found&lt;/H1&gt;\n&lt;H2&gt;Error 404&lt;/H2&gt;\n&lt;/
> > BODY&gt;\n&lt;/HTML&gt;\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
-~----------~----~----~----~------~----~------~--~---

Reply via email to