Search code examples
pythongmailfeedatom-feed

Gmail atom feed stopped working lately?


I have always used the following python 2.7.8 script to visualize the feed of my Gmail inbox. Lately, like a week ago or less, it stopped working and now returns HTTPError: HTTP Error 401: Unauthorized without me having modified it in any way.

import urllib2

user='validusernamehere'
passwd='validpasswordhere'

auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(
    realm='New mail feed',
    uri='https://mail.google.com',
    user='%s@gmail.com' % user,
    passwd=passwd
)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
feed = urllib2.urlopen('https://mail.google.com/mail/feed/atom')
content = feed.read()

print content

raw_input("Press ENTER to quit...")

I can still access my mail feed manually through browser at the address https://mail.google.com/mail/feed/atom

Tried to disable my antivirus, same result.
Tried to run the script from an entirely different machine with the outdated python version 2.6.6, same result.


Solution

  • Change it to:

    auth_handler.add_password(
        realm='mail.google.com',
        uri='https://mail.google.com',
        user='%s@gmail.com' % user,
        passwd=passwd
    )