Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
谷歌登录Pythonywhere_Python_Beautifulsoup_Python Requests_Pythonanywhere - Fatal编程技术网

谷歌登录Pythonywhere

谷歌登录Pythonywhere,python,beautifulsoup,python-requests,pythonanywhere,Python,Beautifulsoup,Python Requests,Pythonanywhere,我正在使用此代码通过请求远程连接到我的google帐户。在本地,它工作得很好,但当我尝试在Pythonywhere(Python3.6+的同一版本,我有一个付费帐户,一个黑客计划)上使用时,它不工作,它根本无法连接到我的google帐户,控制台中没有任何错误消息,你知道问题出在哪里吗 from bs4 import BeautifulSoup import requests class SessionGoogle: def __init__(self, url_login, u

我正在使用此代码通过请求远程连接到我的google帐户。在本地,它工作得很好,但当我尝试在Pythonywhere(Python3.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")

你从来没有实际查看登录后请求的响应,因此谷歌很可能出于某种原因拒绝了你的登录,而你也无从知晓。

也许他们不允许任何传出流量。你能连接到其他域名吗?@t.m.adam我刚试着从Pythonywhere连接到另一个网站,它确实起作用了。也许谷歌已经将你服务器的IP列入黑名单了?你能检查一下你请求的stus代码吗?@t.m.adam我刚刚检查了登录url和身份验证url,他们都返回了一个200响应OK,那有什么问题吗?回复内容是否不同?饼干?请具体说明。