问题
I am getting the following error traceback when my program tries to login to GoogleVoice (from googlevoice import Voice, util
) to send SMS message.
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'
My program has been running successfully for the last several weeks. Every once in a while, the above error would get thrown and the error handling would just try again. Now, it has not had a successful login in several hundred tries.
One issue that I feel may be important is that the program was logging in every ten (10) minutes regardless of whether or not an SMS was sent (rare case, every few days at most).
In the above traceback, You can see that I moved the function call that performed the GoogleVoice login to within the loop only in case its needed. It is still having problems because there is an alarm notification that needs to be sent out.
I tried logging in and out of my Google account, no avail.
Here's a clue --> the following code was copied out of the file identified in the last line of the traceback (source of error):
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
We should note that
galx = re.search(r"name=\"GALX\"\s+value=\"(.+)\"", content).group(1)
is the source of the error and that (this is important) the line immediately above it says
# holy hackjob
回答1:
I have been able to correct the issue. It appears that Google did make a modification:
The patch is here: http://pastebin.com/bxvNjj00
Or you can simply modify voice.py and change the offending line that begins with galx = to this:
galx = re.search(r"name=\"GALX\" type=\"hidden\"\n *value=\"(.+)\"", content).group(1)
回答2:
I'm not very well versed in regex, so I rewrote mine to dice up the string. In case the new modification breaks in the future, a try except statement can be used like this:
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
来源:https://stackoverflow.com/questions/19661031/googlevoice-will-not-programmatically-login-python