Python cgi.parse_qsl导致GAE出现奇怪错误
我希望使用GAE构建一个facebook应用程序。下面的代码Python cgi.parse_qsl导致GAE出现奇怪错误,python,google-app-engine,cgi,Python,Google App Engine,Cgi,我希望使用GAE构建一个facebook应用程序。下面的代码 from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext import webapp from urllib import urlopen, quote import cgi from django.utils import simplejson as json class fbcheck(webapp.Reque
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import webapp
from urllib import urlopen, quote
import cgi
from django.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()
对同一问题的任何建议都应该是
response=cgi.parse_qsl(urlopen(tokenurl.read())
;urlopen返回类AddInfo URL
的实例,该实例可以从中读取,而不是URL的内容。得到它。它应该是response=cgi.parse_qsl(urlopen(tokenurl.read())将您的评论作为答案发布!
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'