0
登錄谷歌AppEngine上使用Python和的urllib2 我已經得到驗證和Sid從https://www.google.com/accounts/ClientLogin 但後來我加了頭,纔看到我不是在洛。登錄到谷歌的AppEngine與蟒蛇
這裏是我的代碼(我是一個新的Python用戶,代碼將是非常糟糕的。):
LOGIN_URL = 'https://www.google.com/accounts/ClientLogin'
EMAIL = '[email protected]'
PASSWORD = 'XXXXX'
print "Your Google account:"
print EMAIL
print "Logging in..."
arequest = urllib2.Request(LOGIN_URL, urlencode({
'service': 'ah',
'Email': EMAIL,
'Passwd': PASSWORD,
}))
f = urllib2.urlopen(arequest)
lines = f.read().split()
auth = lines[2][5:]
sid = lines[0][4:]
print "Google Logged in"
#print auth and sid,and you will find the code above is right
brequest = urllib2.Request("https://appengine.google.com")
brequest.add_header('User-Agent', 'Here is Chrome's UA')
brequest.add_header('Content-Type', 'application/x-www-form-urlencoded')
brequest.add_header('Authorization', 'GoogleLogin auth=' + auth)
brequest.add_header('Cookie', 'SID=' + sid)
brequest.add_header('Referer', 'https://appengine.google.com/start')
print "Opening with Auth info..."
bresponse = urllib2.urlopen(brequest)
print bresponse.read()
#The output shows that I haven't logged in.
我以前在Firefox Firebug查看頭信息,餅乾不僅是上述SID。 我該怎麼辦?下一個需要登錄的表現(我沒有寫過),我應該怎麼寫? 它在我的筆記本電腦上吃午飯,所以我不使用appengieg的lib像urlfetch。 非常感謝!