当我的程序尝试登录 GoogleVoice(from googlevoice import Voice, util
)以发送 SMS 消息时,我收到以下错误回溯。
File "C:\Users\ble1usb\Dropbox\Git\ers-dataanalyzzer\MainFrame.py", line 38, in call_mainframe
ah.compare_status() # compares current status with historical status. alerts alarm team if necessary
File "C:\Users\ble1usb\Dropbox\Git\ers-dataanalyzzer\alarm_handler.py", line 61, in compare_status
self.megaphone = megaphone.MegaPhone() # Am I going to have problems putting this here? I am getting relentless login fails due to the shitty googlevoice login
File "C:\Users\ble1usb\Dropbox\Git\ers-dataanalyzzer\megaphone.py", line 18, in __init__
self.voice.login(bl_google_credentials[0], bl_google_credentials[1])
File "C:\Python27\lib\site-packages\googlevoice\voice.py", line 70, in login
galx = re.search(r"name=\"GALX\"\s+value=\"(.+)\"", content).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
我的程序在过去几周内一直在成功运行。每隔一段时间,就会抛出上述错误,错误处理会重试。现在,它已经尝试了数百次,但仍未成功。
我认为可能重要的一个问题是程序每十 (10) 分钟登录一次,无论是否发送 SMS(极少数情况,最多每隔几天)。
在上面的回溯中,您可以看到我将执行 GoogleVoice 登录的函数调用移动到循环内,以防万一。它仍然有问题,因为有一个警报通知需要发送出去。
我尝试登录和退出我的 Google 帐户,但无济于事。
这是一条线索 --> 以下代码是从回溯的最后一行(错误来源)中标识的文件中复制出来的:
def login(self, email=None, passwd=None):
"""
Login to the service using your Google Voice account
Credentials will be prompted for if not given as args or in the ``~/.gvoice`` config file
"""
if hasattr(self, '_special') and getattr(self, '_special'):
return self
if email is None:
email = config.email
if email is None:
email = input('Email address: ')
if passwd is None:
passwd = config.password
if passwd is None:
from getpass import getpass
passwd = getpass()
content = self.__do_page('login').read()
# holy hackjob
galx = re.search(r"name=\"GALX\"\s+value=\"(.+)\"", content).group(1)
self.__do_page('login', {'Email': email, 'Passwd': passwd, 'GALX': galx})
del email, passwd
try:
assert self.special
except (AssertionError, AttributeError):
raise LoginError
return self
我们应该注意到
galx = re.search(r"name=\"GALX\"\s+value=\"(.+)\"", content).group(1)
是错误的来源,并且(这很重要)它上面的那一行是
#神圣的 hackjob
最佳答案
我已经能够纠正这个问题。看来 Google 确实做了修改:
补丁在这里:http://pastebin.com/bxvNjj00
或者您可以简单地修改 voice.py 并将以 galx = 开头的违规行更改为:
galx = re.search(r"name=\"GALX\"type=\"hidden\"\n *value=\"(.+)\"", content).group(1)
关于python - googlevoice 不会以编程方式登录 (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19661031/