python - Feedparser - KeyError: 'fullcount' -


i have tried follow this guide. making physical gmail notifier. when entered same code found 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 not sure why , thats why im asking. using windows 7, python 2.7.3, feedparser 5.1.3 , pyserial 2.6

here full code:

import serial, sys, feedparser  #settings - change these match account details username="mymain@gmail.com" password="mypassword" proto="https://" server="mail.google.com" path="/gmail/feed/atom"  serialport = "com3" # change serial port!  # set 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 serial port if newmails > 0: ser.write('m') else: ser.write('n')  # close serial port ser.close() 

just took @ repl. code work as-is me. however, able reproduce error entering incorrect password.

this feedparser.parse()['feed'] looks if fail authenticate:

>>> feedparser.parse(proto + username + ":" + incorrect_password + "@" + server + path)['feed'] {'summary': u'<h1>unauthorized</h1>\n<h2>error 401</h2>'} >>>   

this should if authenticate properly:

>>> import pprint >>> pprint.pprint(feedparser.parse(proto + username + ":" + password + "@" + server + path)['feed']) {'fullcount': u'0',  'link': u'http://mail.google.com/mail',  'links': [{'href': u'http://mail.google.com/mail',             'rel': u'alternate',             'type': u'text/html'}],  'subtitle': u'new messages in gmail inbox',  'subtitle_detail': {'base': u'https://mail.google.com/mail/feed/atom',                      'language': none,                      'type': u'text/plain',                      'value': u'new messages in gmail inbox'},  'title': u'gmail - inbox xxxxxxx@gmail.com',  'title_detail': {'base': u'https://mail.google.com/mail/feed/atom',                   'language': none,                   'type': u'text/plain',                   'value': u'gmail - inbox xxxxxxx@gmail.com'},  'updated': u'2013-03-01t20:11:03z',  'updated_parsed': time.struct_time(tm_year=2013, tm_mon=3, tm_mday=1, tm_hour=20, tm_min=11, tm_sec=3, tm_wday=4, tm_yday=60, tm_isdst=0)} >>>  

you should print out result of feedparser.parse() check if indeed problem have, suspect making sure username/password correct fix problem


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -