当我的程序尝试登录到GoogleVoice (from googlevoice import Voice, util
)发送SMS消息时,我收到以下错误回溯。
File "C:Usersble1usbDropboxGiters-dataanalyzzerMainFrame.py", line 38, in call_mainframe
ah.compare_status() # compares current status with historical status. alerts alarm team if necessary
File "C:Usersble1usbDropboxGiters-dataanalyzzeralarm_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:Usersble1usbDropboxGiters-dataanalyzzermegaphone.py", line 18, in __init__
self.voice.login(bl_google_credentials[0], bl_google_credentials[1])
File "C:Python27libsite-packagesgooglevoicevoice.py", line 70, in login
galx = re.search(r"name="GALX"s+value="(.+)"", content).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
在过去的几周里,我的程序一直成功运行。每隔一段时间,上述错误就会被抛出,错误处理会再次尝试。现在,它在数百次尝试中都没有成功登录。
我认为可能很重要的一个问题是,无论是否发送短信,该程序每十 (10) 分钟登录一次(极少数情况,最多每隔几天)。
在上面的回溯中,您可以看到我只是在需要时将执行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)
是错误的源,并且(这很重要)它上面的行说
# holy hackjob
我已经能够纠正这个问题。看来谷歌确实做了一个修改:
补丁在这里:http://pastebin.com/bxvNjj00
或者您可以简单地修改 voice.py 并以 galx = 开头的违规行更改为:
galx = re.search(r"name=\"GALX\" type=\"hidden\" *value=\"(.+)\", content).group(1)
精通正则表达式,所以我重写了我的字符串。如果将来新的修改中断,可以像这样使用 try except 语句:
try:
galx = re.search(r"name="GALX" type="hidden"n *value="(.+)"", content).group(1)
except:
galx = ''.join(e for e in content if e.isalnum()) # Remove special characters (leaving only letters & numbers)
galx = galx[galx.index("GALX"):] # Grab everything from GALX forward
galx = galx[:galx.index("input")] # Truncate at input (first word after GALX value)
galx = galx[galx.index("value")+5:] # Extract GALX value