I have tried to follow this guide. It is about making a physical gmail notifier. When I entered the same code it found an error:
Traceback (most recent call last):
File "C:/Python27/Projects/gmailnotifier.py", line 20, in <module>
)["feed"]["fullcount"])
File "C:\Python27\lib\site-packages\feedparser-5.1.3-py2.7.egg\feedparser.py", line 375, in __getitem__
return dict.__getitem__(self, key)
KeyError: 'fullcount'
I am not sure why and thats why im asking. I am using windows 7, python 2.7.3, feedparser 5.1.3 and pyserial 2.6
Here is the full code:
import serial, sys, feedparser
#Settings - Change these to match your account details
USERNAME="mymain@gmail.com"
PASSWORD="mypassword"
PROTO="https://"
SERVER="mail.google.com"
PATH="/gmail/feed/atom"
SERIALPORT = "COM3" # Change this to your serial port!
# Set up serial port
try:
ser = serial.Serial(SERIALPORT, 9600)
except serial.SerialException:
sys.exit()
newmails = int(feedparser.parse(
PROTO + USERNAME + ":" + PASSWORD + "@" + SERVER + PATH
)["feed"]["fullcount"])
# Output data to serial port
if newmails > 0: ser.write('M')
else: ser.write('N')
# Close serial port
ser.close()
Just took a look at that from a REPL. The code will work as-is for me. However, I was able to reproduce your error by entering an incorrect password.
This is what
feedparser.parse()['feed']
looks like if you fail to authenticate:This is what it should look like if you do authenticate properly:
You should print out the result of
feedparser.parse()
to check if this is indeed the problem you have, but I suspect that simply making sure your username/password are correct will fix your problem