Karan Thakkar
Karan Thakkar

Reputation: 414

Error accessing Gmail Atom feeds using feedparser

I was having a problem accessing my Gmail Atom feeds using feedparser module. For a non-password protected fees like a blog, for example,

import feedparser

d = feedparser.parse('http://karanjthakkar.wordpress.com/feed/')
print d.feed.title

The values that the feedparser module returned were correct. However when I used it using this to access my Gmail feed,

import urllib2, feedparser

def main():
 pwdmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
 pwdmgr.add_password("New mail feed", 'http://mail.google.com/', "karanjthakkar", "my-password")
 auth = urllib2.HTTPBasicAuthHandler(pwdmgr)
 opener = urllib2.build_opener(auth)
 data = opener.open('http://mail.google.com/mail/feed/atom')
 d = feedparser.parse(data)
 print d

if __name__ == '__main__'
 main()

I got an Error 401 in the feed that was captured. This is what was captured:

screenshot

Am I missing something? I am not from a CS background so whatever I know is what I've read around. I intend to use the Gmail feeds captured to check the number of unread messages and display them using an Arduino.

Upvotes: 0

Views: 1809

Answers (1)

Yunchi
Yunchi

Reputation: 5537

I had no luck with HTTPDigestAuthHandler, but was able to get it working with HTTPBasicAuthHandler.

import urllib2, feedparser

pwdmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
pwdmgr.add_password("New mail feed", 'http://mail.google.com/', username, password)
auth = urllib2.HTTPBasicAuthHandler(pwdmgr)
opener = urllib2.build_opener(auth)
data = opener.open('http://mail.google.com/mail/feed/atom')
d = feedparser.parse(data)
print d

Upvotes: 3

Related Questions