我已尝试遵循本指南。它是关于制作一个物理 gmail 通知器。当我输入相同的代码时,它发现了一个错误:
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'
我不知道为什么,这就是我问的原因。我正在使用 Windows 7、python 2.7.3、feedparser 5.1.3 和 pyserial 2.6
这是完整的代码:
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()