1

当我的程序尝试登录 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'

我的程序在过去几周内一直成功运行。每隔一段时间,就会抛出上述错误,错误处理会再次尝试。现在,它在数百次尝试中都没有成功登录。

我认为可能很重要的一个问题是,无论是否发送 SMS,程序每十 (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

4

2 回答 2

4

我已经能够纠正这个问题。看来谷歌确实做了修改:

补丁在这里: http: //pastebin.com/bxvNjj00

或者您可以简单地修改 voice.py 并将以 galx = 开头的违规行更改为:

galx = re.search(r"name=\"GALX\" type=\"hidden\"\n *value=\"(.+)\"", content).group(1)

于 2013-10-29T16:46:13.833 回答
0

我对正则表达式不是很精通,所以我重写了我的以切分字符串。如果将来新的修改中断,可以像这样使用 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
于 2013-10-31T14:18:17.233 回答