开发者

cgi.parse_qsl causing weird error with GAE

I wish to build a facebook app using GAE. The following code

    from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import webapp

from urllib import urlopen, quote
import cgi
from d开发者_JAVA技巧jango.utils import simplejson as json

class fbcheck(webapp.RequestHandler):
    def get(self):
        appid = 'XXX'
        appsecret = 'XXXX'
        myurl = 'XXX'

        code = self.request.get("code")
        if not code :
            dialogurl = 'https://facebook.com/dialog/outh?client_id=%s&redirect_uri=%s'%(appid,quote(myurl))
            self.response.out.write('<script> top.location.href="%s"</script>'%(dialogurl,))
        tokenurl = 'https://graph.facebook.com/oauth/access_token?client_id=%s&redirect_uri=%s&client_secret=%s&code=%s'%(appid,quote(myurl),appsecret,code)
        response = cgi.parse_qsl(urlopen(tokenurl))
        graphurl = 'https://graph.facebook.com/me?access_token=%s'%(response['access_token'],)
        user = json.loads(urlopen(graphurl))
        self.response.out.write('Hi %s'(user.name,))
        #self.response.out.write('hi')

application = webapp.WSGIApplication([('/', fbcheck),], debug=True)
def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()

It gives me the following error

    Traceback (most recent call last):
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 700, in __call__
    handler.get(*groups)
  File "/base/data/home/apps/s~dotsnboxes/1.351361343827624192/game.py", line 22, in get
    response = cgi.parse_qsl(urlopen(tokenurl))
  File "/base/python_runtime/python_dist/lib/python2.5/cgi.py", line 213, in parse_qsl
    pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
AttributeError: addinfourl instance has no attribute 'split'

Any suggestions for the same?


should be response = cgi.parse_qsl(urlopen(tokenurl).read()); urlopen returns an instance of class addinfourl which can be read from, not the contents of the URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜