Python Feedparser - KeyError:'fullcount'

时间:2014-07-22 20:33:04

标签: python openwrt feedparser arduino-yun

这就是我的要求。我在arduino yun上使用mac osx 10.9,python 2.7.3,feedparser 5.1.3,我试图使用下面的python脚本检查我的gmail并且它会一直返回错误代码如下。
这是完整的代码:

root@ArduinoYun:~# vi 1.py
#!/usr/bin/python
import feedparser

USERNAME="mygmail@gmail.com"
PASSWORD="mypsw"
PROTO="https://"
SERVER="mail.google.com"
PATH="/gmail/feed/atom"
print(feedparser.parse(PROTO+USERNAME+":"+PASSWORD+"@"+SERVER+PATH)) 

root@ArduinoYun:~# ./1.py
{'feed': {}, 'bozo': 1, 'bozo_exception': URLError('unknown url type: https',), 'entries': []}

安装openssl pkg后,上面的问题解决了,但还有一个新问题...... 代码如下:

...
pprint.pprint(feedparser.parse(PROTO+USERNAME+":"+PASSWORD+"@"+SERVER+PATH)["feed"])

root@ArduinoYun:~# ./1.py
{'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 your Gmail Inbox',
 'subtitle_detail': {'base': u'https://mail.google.com/mail/feed/atom',
                     'language': None,
                     'type': u'text/plain',
                     'value': u'New messages in your Gmail Inbox'},
 'title': u'Gmail - Inbox for USERNAME@gmail.com',
 'title_detail': {'base': u'https://mail.google.com/mail/feed/atom',
                  'language': None,
                  'type': u'text/plain',
                  'value': u'Gmail - Inbox for USERNAME@gmail.com'},
 'updated': u'2014-07-22T21:08:57Z',
 'updated_parsed': time.struct_time(tm_year=2014, tm_mon=7, tm_mday=22, tm_hour=21, tm_min=8,    
tm_sec=57, tm_wday=1, tm_yday=203, tm_isdst=0)}

似乎一切都好。但是当剧本修改如下:

...
newmail = int(feedparser.parse(PROTO+USERNAME+":"+PASSWORD+"@"+SERVER+PATH)["feed"]  
["fullcount"])
root@ArduinoYun:~# ./1.py
Traceback (most recent call last):
  File "./1.py", line 10, in <module>
 newmail = int(feedparser.parse(PROTO+USERNAME+":"+PASSWORD+"@"+SERVER+PATH)["feed"]   
["fullcount"])
  File "/usr/lib/python2.7/site-packages/feedparser-5.1.3-py2.7.egg/feedparser.py", line 375,   
in __getitem__
    return dict.__getitem__(self, key)
KeyError: 'fullcount'

0 个答案:

没有答案