小编Hoo*_*stu的帖子

循环10小时后的KeyError

在15秒循环后,我在下面的脚本中得到以下KeyError,完美地工作了10个小时.为什么一个关键错误只会在每15秒运行10个小时后出现一次?

错误:

Traceback (most recent call last):

  File "C:\venderFix.py", line 33, in <module>

    if j['results']:

KeyError: 'results'
Run Code Online (Sandbox Code Playgroud)

码:

import json
import urllib
from pprint import pprint
import time
from arduino import Arduino

vendtime = 0.2                                           
delayTime = 15                                               
searchTerm = 'happy'                      

A = Arduino('COM3') #This will need to be COM3               
A.output([12]) #Output on pin 12                             

countTweet = 0
#To test Twitter for consistancy 
tweet= 0
noTweet= 0



#the infinate loop
while True:

    #j contains the JSON we load from the …
Run Code Online (Sandbox Code Playgroud)

python keyerror

2
推荐指数
1
解决办法
672
查看次数

为什么这个Python脚本会崩溃?

这个Python脚本可以运行好几天然后崩溃,你知道为什么会发生这种情况或如何调试它吗?它连接到一个Arduino,当它通过串行接收'1'时发送一个高电平引脚.该脚本在计算机启动时启动,应该永久运行.如果它确实崩溃了,我没有办法重新启动脚本,因为计算机在远程位置.

import json
import urllib
from pprint import pprint
import time
import serial

#to collect the first tweet without telling the arduino
countTweet = 0
tweet= 0
noTweet= 0

#the infinate loop
while True:
    #the connection to the arduino
    ser = serial.Serial('COM3',9600)
    #not connected to arduino before connection is made
    connected = False

    #loop until the arduino is connected
    while not connected:
        serin = ser.read()
        connected = True
    #debug arduino connection
    if connected == True:
        pprint('connected to arduino')

    #j contains …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

1
推荐指数
1
解决办法
1121
查看次数

标签 统计

python ×2

keyerror ×1

python-2.7 ×1