libgmail failure

Hamish Macpherson hamstu at gmail.com
Thu Aug 23 05:59:34 CEST 2007


On Aug 21, 5:07 pm, "james.p.n... at gmail.com" <james.p.n... at gmail.com>
wrote:
> Hey all,
>
> I've been usinglibgmailto send out automated notification emails for
> my company's nightly regression testing.  Last night these emails
> started failing, though the python code has not changed.  I updated to
> the latestlibgmail, but that isn't helping.  I've logged in to the
> email account directly, and the account is still working fine.
>
> The error I get is "HTTP Error 400: Bad Request" when using
> gmailAccount.login().  This doesn't throw an exception, just prints
> the error.  The code crashes outright when it tries to send mail.
>
> This code has been up and running for several months and just started
> failing last night.  Does anyone have an idea what's going on?
>
> The code and error follow (fairly short :-)
>
> Thanks much,
> James
>
> Code:
> -------------------------------------------------------------------------------------------------------
> def send(TO_LIST,SUBJECT,MESSAGE):
>     GA =libgmail.GmailAccount("xxx... at gmail.com","xxxxxxx")
>     try:
>         print "Logging in"
>         GA.login()
>     exceptlibgmail.GmailLoginFailure:
>         print "\nLogin failed. (Wrong username/password?)"
>     else:
>         print "Log in successful.\n"
>         for RX in TO_LIST:
>             MSG =libgmail.GmailComposedMessage(RX,SUBJECT,MESSAGE)
>             if GA.sendMessage(MSG):
>                 print "Message successfully sent to `%s` ." % RX
>             else:
>                 print "Could not send message."
> -------------------------------------------------------------------------------------------------------
>
> Output:
> -------------------------------------------------------------------------------------------------------
> Logging in
> HTTP Error 400: Bad Request
> Log in successful.
>
> No messages found
> Traceback (most recent call last):
>   File "C:\projects\physware\testCases\PythonTestScripts
> \SendEmail.py", line 58, in <module>
>     main()
>   File "C:\projects\physware\testCases\PythonTestScripts
> \SendEmail.py", line 55, in main
>     send(TO_LIST,SUB,MSG)
>   File "C:\projects\physware\testCases\PythonTestScripts
> \SendEmail.py", line 39, in send
>     if GA.sendMessage(MSG):
>   File "C:\projects\physware\testCases\PythonTestScripts\libgmail.py",
> line 588, in sendMessage
>     U_ACTION_TOKEN: self._getActionToken(),
>   File "C:\projects\physware\testCases\PythonTestScripts\libgmail.py",
> line 563, in _getActionToken
>     at = self._cookieJar._cookies[ACTION_TOKEN_COOKIE]
> KeyError: 'GMAIL_AT'
> -------------------------------------------------------------------------------------------------------

I believe I've found a (temporary) fix in this forum thread:
http://www.castlecops.com/p984588-HTTP_Error_400_when_using_gknujon.html

Pasted here for posterity;

---
Edit the libgmail.py file.

In the function

def login(self)


change the following text:
Code:
try:
    link = re.search(RE_PAGE_REDIRECT, pageData).group(1)
    redirectURL = urllib.unquote(link)


to add the extra line:
Code:
try:
    link = re.search(RE_PAGE_REDIRECT, pageData).group(1)
    redirectURL = urllib.unquote(link)
    redirectURL = redirectURL.replace('\\x26','&')
---

Must have been some small change in gmail's redirect that put it off.




More information about the Python-list mailing list