我有一个Google App Engine应用程序 - http://mylovelyapp.appspot.com/ 它有一个页面 - mylovelypage
目前,页面就是这样 self.response.out.write('OK')
如果我在我的计算机上运行以下Python:
import urllib2
f = urllib2.urlopen("http://mylovelyapp.appspot.com/mylovelypage")
s = f.read()
print s
f.close()
Run Code Online (Sandbox Code Playgroud)
它打印"OK"
问题是如果我login:required在应用程序的yaml中添加到此页面
然后打印出Google帐户登录页面的HTML
我尝试过"正常"的身份验证方法.例如
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(None,
uri='http://mylovelyapp.appspot.com/mylovelypage',
user='billy.bob@gmail.com',
passwd='billybobspasswd')
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
Run Code Online (Sandbox Code Playgroud)
但它没有任何区别 - 我仍然得到登录页面的HTML.
我已经尝试了Google的ClientLogin auth API,但我无法让它工作.
h = httplib2.Http()
auth_uri = 'https://www.google.com/accounts/ClientLogin'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
myrequest = "Email=%s&Passwd=%s&service=ah&source=DALELANE-0.0" % ("billy.bob@gmail.com", "billybobspassword")
response, content = h.request(auth_uri, 'POST', body=myrequest, headers=headers)
if response['status'] == '200':
authtok = re.search('Auth=(\S*)', …Run Code Online (Sandbox Code Playgroud)