我使用这段代码远程连接到我的谷歌帐户使用请求。在本地,它可以很好地工作,但是当我尝试在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")发布于 2018-05-09 14:35:52
实际上,你从来没有看过登录帖子请求的响应,所以Google完全有可能因为某种原因拒绝了您的登录,而且您也无法知道。
https://stackoverflow.com/questions/50251870
复制相似问题