Google 在 Pythonanywhere 上登录

Google login on Pythonanywhere

我正在使用此代码通过请求远程连接到我的 google 帐户。在本地它完美地工作但是当我试图在 Pythonanywhere 上使用时(python 3.6 的相同版本 + 我有一个付费帐户,一个黑客计划)它不起作用,它没有连接到我的google 帐户,控制台中没有任何错误消息,您知道可能是什么问题吗?

from bs4 import BeautifulSoup
import requests    

class SessionGoogle:
    def __init__(self, url_login, url_auth, login, pwd):
        self.ses = requests.session()
        login_html = self.ses.get(url_login)
        soup_login = BeautifulSoup(login_html.content).find('form').find_all('input')
        my_dict = {}
        for u in soup_login:
            if u.has_attr('value'):
                my_dict[u['name']] = u['value']
        # override the inputs without login and pwd:
        my_dict['Email'] = login
        my_dict['Passwd'] = pwd
        self.ses.post(url_auth, data=my_dict)

    def get(self, URL):
        return self.ses.get(URL).text

url_login = "https://accounts.google.com/ServiceLogin"
url_auth = "https://accounts.google.com/ServiceLoginAuth"
session = SessionGoogle(url_login, url_auth, "myGoogleLogin", "myPassword")
print session.get("http://plus.google.com")

您实际上从未查看登录 post 请求的响应,因此 Google 很可能出于某种原因拒绝您的登录,而您无从知晓。