0

I don't succeed to parse gmail Atom feed using feedparser with python 3.6 on windows 10 and neither on a raspberry pi running python 3.5 with ubuntu.

For the gmail account I'd like to access atom feed, I have previously setup 2 step authentification and then a password for other device ( raspberry pi )

When authentifying myself, I use the device password used successfully by ssmtp on raspberry pi to send emails from that account. With the same password, I also succeed to get the atom feed from firefox, but I guess it is still an authentification problem.

Here is the code executed and the error message on win10 with python 3.6 :

#!/usr/bin/env python
import feedparser

USERNAME = "user@gmail.com"
PASSWORD = "password"
response = feedparser.parse("https://" + USERNAME + ":" + PASSWORD + "@mail.google.com/gmail/feed/atom")
unread_count = int(response["feed"]["fullcount"])

Result:

Traceback (most recent call last):
  File "C:/Users/cedric/Google Drive/raspberry-pi/feedparser_example2.py", line 7, in <module>
    unread_count = int(response["feed"]["fullcount"])
  File "C:\Users\cedric\AppData\Local\Programs\Python\Python36\lib\site-packages\feedparser.py", line 356, in __getitem__
    return dict.__getitem__(self, key)
KeyError: 'fullcount'

If I run it with raspberry pi with python3.5 here is the error message:

Traceback (most recent call last):
  File "/home/ced/Bureau/secu/feedparser_example.py", line 14, in <module>
    unread_count = int(response["feed"]["fullcount"])
  File "/usr/local/lib/python3.5/dist-packages/feedparser.py", line 357, in __getitem__
    return dict.__getitem__(self, key)
KeyError: 'fullcount'

Does someone have an idea about this ? Thanks for your help

  • Can you clarify why your code should work (relevant documentation, resources, etc.). Because according to [https://developers.google.com/gmail/api/quickstart/python], oauth2 has to be completed]. – rushi Jul 23 '17 at 02:07
  • According to this site http://mitchtech.net/connect-raspberry-pi-to-gmail-facebook-twitter-more/ , it should work and actually it doesn't. – Ray Gllisse Jul 23 '17 at 10:00
  • That post is from 2012, the APIs (or whichever interface used in the snippet) might have changed. IMHO you should try to understand current docs and make tweaks at appropriate places. – rushi Jul 23 '17 at 10:49
  • Finally, I have used someone else's code: , https://gist.github.com/jasonrdsouza/1674794 that works retrieving email with IMAP, the password that works is a device password defined for gmail account. The regular user password can't be used. Nevertheless, If someone else finds how to use atom feed with device password, I am still interested as with IMAP I get a full list of emails, and not specifically the new ones. – Ray Gllisse Jul 23 '17 at 12:06

0 Answers0