仅在 Linux 上出错,在 Mac 上没有错误:'kwargs'出现意外的关键字参数



我在Python中写了一个推送通知调度程序,以进行研究,该计划将处理通过Node .js发送通知。它在我的Mac上很漂亮,没有问题。我在其他地方构建了一台服务器来处理调度程序,因为它一直在打开。由于我无法控制的原因,该服务器运行Debian Wheezy。但是,每当我尝试运行代码时,我都会得到:

File "scheduler.py", line 148, in send_notifications
    s.enter(5, 1, notification, kwargs={'notify': 'Welcome to the Study!'})
TypeError: enter() got an unexpected keyword argument 'kwargs'

仍然可以在我的Mac上工作。我已经检查了一下,以确保我所有的导入库都是通过PIP3下载的,但是我无法弄清楚我的问题是什么。我已经在Stackoverflow和其他各种来源上检查了其他错误的人,但是我不确定他们是否有与我的问题相似的问题,主要是课堂呼叫问题,我认为这不是那样。我已经附加了代码,尽管我不确定是否有帮助。我的意思是,这不是世界上最干净的代码,但是我比Python更加流利的移动开发人员。有什么建议吗?

import time #this need is obvious 
import datetime as dt
import sched
from datetime import datetime
from datetime import timedelta
from subprocess import call #needed to call terminal commands
#Don't forget to chmod +x this python application so that you can sudo out.
#this order of the notifications that will be run, in an array
listOfNotificationNames = ['weather', 'sched', 'thermo', 'manualKitchen', 'frontDoor', 'garage', 'window', 'solar', 'backDoor', 'garage', 'frontDoor', 
    'manualKitchen', 'solar', 'energyCom', 'alarm', 'weather', 'sched', 'solar', 'manualKitchen', 'thermo', 'frontDoor', 'garage', 'manualKitchen', 
    'autokitchen', 'backDoor', 'frontDoor', 'manualKitchen', 'garage', 'sensor', 'solar', 'window', 'energyCom', 'alarm', 'weather', 'sched', 'thermo', 
    'manualKitchen', 'frontDoor', 'garage', 'tvenergy', 'window', 'garage', 'backDoor', 'solar', 'frontDoor', 'manualKitchen', 'energyCom', 'alarm', 
    'weather', 'sched', 'solar', 'thermo', 'manualKitchen', 'frontDoor', 'manualKitchen', 'garage', 'backDoor', 'milk', 'garage', 'frontDoor', 'manualKitchen', 
    'autokitchen', 'energyCom', 'alarm', 'weather', 'solar', 'sched', 'thermo', 'manualKitchen', 'backDoor', 'garage', 'window', 'frontDoor', 'autokitchen', 
    'manualKitchen', 'frontDoor', 'solar', 'garage', 'energyCom', 'alarm']
#Dictionary of what the above short names connect to. Take short names, and connect them to full length notifications
listOfNotificationText = {'garage': 'Your garage door has opened', 'frontDoor': 'Your front door has opened', 'backDoor': 'Your back door has opened', 
    'energyCom': 'Your daily energy consumption is: 33.5 kWh', 'thermo': 'Your thermostat has been changed to 73 degrees', 'weather': 'The weather for the day is: Cloudy and cool',
    'solar': 'The solar cell battery status is 52%', 'alarm': 'Tomorrow’s alarm is set for 9am', 'sched': 'Today’s schedule includes: ', 
    'milk': 'Don’t forget to get milk on your way home today.', 'manualKitchen': 'A light in the kitchen has been turned on', 
    'sensor': 'The sensor above the door is not responding.  Please check on its status.', 
    'tvenergy': 'Your television utilizes 2 watts of energy when not in use.  It will be powered off when not in use from now on.',
    'window': 'The bedroom window has been opened to cool the room.'}
#test code, can be used to test the notification system
time1 = now+timedelta(seconds=30)
time2 = now+timedelta(seconds=60)
time3 = now+timedelta(seconds=90)
testList = [dt.datetime(now.year, now.month, now.day, time1.hour, time1.minute, time1.second), 
    dt.datetime(now.year, now.month, now.day, time2.hour, time2.minute, time2.second), 
    dt.datetime(now.year, now.month, now.day, time3.hour, time3.minute, time3.second)]
#empty list to be filled
listOfTimeDelays = [0, 0, 0]
#takes all the lists above, and figures out how long each of them are from when I started the study.
#This creates a giant list of delays from the day I hit start
def calculateMinutesIntoSeconds(testList, listOfTimeDelays):
    i = 0
    for member in testList:
        print(member)
        listOfTimeDelays[i] = ((member-dt.datetime(now.year, now.month, now.day, now.hour, now.minute, now.second)).total_seconds())
        print(listOfTimeDelays[i])
        i= i+1
# Note that you have to specify path to script
#This call runs the notification.
#Create a scheduler.
s = sched.scheduler(time.time, time.sleep)
#Takes a notification text and sends ends out the notification.
def notification(notify='failure to properly fill notification'):
    call(["node", "app.js", notify, "send this data"])
#test code. Mostly ignore this
def print_time(a='default'):
    print("From print_time", time.time(), a)

def send_notifications():
    #calculate all of the many times delays
    calculateMinutesIntoSeconds(testList, listOfTimeDelays)
    # calculateMinutesIntoSeconds(listOfTimesDay1, listOfTimeDelays)
    # calculateMinutesIntoSeconds(listOfTimesDay2, listOfTimeDelays)
    # calculateMinutesIntoSeconds(listOfTimesDay3, listOfTimeDelays)
    # calculateMinutesIntoSeconds(listOfTimesDay4, listOfTimeDelays)
    # calculateMinutesIntoSeconds(listOfTimesDay5, listOfTimeDelays)
    print("Time marker for beginning of study: ", time.time())
    #counter needed for calls
    i = 0
    #Just notify people that the study has started.
    s.enter(5, 1, notification, kwargs={'notify': 'Welcome to the Study!'})
    #This for loop fills the scheduler with every notification that needs to be sent.
    for member in listOfTimeDelays:
        #takes one of the time delays, a priority (I just made them all 1), and then sends the right notification
        s.enter(member, 1, notification, kwargs={'notify': listOfNotificationText[listOfNotificationNames[i]]})
        #Incriments the counter to make sure you get the next notification
        i = i+1
    #runs the scheduler
    s.run()
    #Marks the end of the study
    print("Time marker for end of study: ",time.time())
#Calls the above method
send_notifications()

更新:

hmm,经过进一步检查,看起来像Wheezy系统默认为3.2,并且不会接受任何比这更高的请求。看起来它接受了"参数",但是正如克劳斯所建议的那样,参数还需要通知与已发送通知的区域相同。

所以现在看起来像

s.enter(5, 1, notification, argument={'notify: Welcome to the Study!'})
    #This for loop fills the scheduler with every notification that needs to be sent.
    for member in listOfTimeDelays:
        notification = 'notify: ' + listOfNotificationText[listOfNotificationNames[i]]
        #takes one of the time delays, a priority (I just made them all 1), and then sends the right notification
        s.enter(member, 1, notification, argument={notification)
        #Incriments the counter to make sure you get the next notification
        i = i+1

感谢您对此的帮助。

sched.Scheduler仅接受python 3.3的 kwargs参数。我想您正在Debian机器上运行较旧版本。

最新更新