仅在 Linux 上出错,而不在 Mac 上出错:得到了意外的关键字参数 'kwargs'
Error only on Linux, not on Mac: Got an unexpected keyword argument 'kwargs'
我在 python 中写了一个推送通知调度程序用于研究,它将通过 NODE .js 处理发送通知。它在我的 Mac 上运行良好,没问题。我在别处构建了一个服务器来处理调度程序,因为它始终处于打开状态。由于我无法控制的原因,服务器 运行s 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 下载,但我无法弄清楚我的问题是什么。我已经在 Whosebug 和其他各种来源上检查了其他人的这个错误,但我不确定他们是否遇到了与我的问题类似的问题,主要是 class 调用问题,我不认为就是这样。我附上了代码,虽然我不确定这是否有帮助。我的意思是,它不是世界上最干净的代码,但我在移动开发方面比 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()
更新:
嗯,经过进一步检查,Wheezy 系统似乎默认设置为 3.2,并且不会接受高于此值的任何请求。看起来它接受 "argument" 但正如克劳斯建议的那样,参数也需要通知与发送的通知位于同一区域。
所以现在看起来像
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
只接受一个 kwargs
参数 from Python 3.3 onwards。我猜你的 Debian 机器上 运行 是旧版本。
我在 python 中写了一个推送通知调度程序用于研究,它将通过 NODE .js 处理发送通知。它在我的 Mac 上运行良好,没问题。我在别处构建了一个服务器来处理调度程序,因为它始终处于打开状态。由于我无法控制的原因,服务器 运行s 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 下载,但我无法弄清楚我的问题是什么。我已经在 Whosebug 和其他各种来源上检查了其他人的这个错误,但我不确定他们是否遇到了与我的问题类似的问题,主要是 class 调用问题,我不认为就是这样。我附上了代码,虽然我不确定这是否有帮助。我的意思是,它不是世界上最干净的代码,但我在移动开发方面比 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()
更新:
嗯,经过进一步检查,Wheezy 系统似乎默认设置为 3.2,并且不会接受高于此值的任何请求。看起来它接受 "argument" 但正如克劳斯建议的那样,参数也需要通知与发送的通知位于同一区域。
所以现在看起来像
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
只接受一个 kwargs
参数 from Python 3.3 onwards。我猜你的 Debian 机器上 运行 是旧版本。