我已经完成了Python& Flask应用程序和我面临一个奇怪的错误。我收到TypeError: 'bool' object is not callable
错误,但我的Flask路由中的所有代码都按预期工作。我的Flask日志中出现500错误,但所有代码片段都正常工作(goalHorn,goalLights& set_power_state)。
非常感谢任何帮助。
@app.route('/tests/full', methods=['POST'])
def performTestsFull():
print('Full Test Password POSTed - ', request.form['password'])
if request.form['password'] == config.post_test:
print('Passowrd verified - Testing Lights & Sounds!')
if Receiver.get_power_state() == 'STANDBY':
powerFlipped = True
print('Receiver was off - powerFlipped is', powerFlipped)
Receiver.set_power_state('ON')
time.sleep(2)
LightsSounds.goalHorn('enable')
LightsSounds.goalLights('enable')
time.sleep(config.goal_time)
LightsSounds.goalHorn('disable')
LightsSounds.goalLights('disable')
# GPIO.cleanup()
if powerFlipped is True:
Receiver.set_power_state('OFF')
print('Receiver was off - turning it back off now...')
return True
else:
print('Incorrect Password - NOT Testing Lights & Sounds!')
return False
这是调用此路由的HTML模板 -
$("#both-test-disabled").bind('click tap', function() {
promptPW = prompt("Enter password to perform full test...");
// if(confirm("Goal Horn is disabled - are you sure you want to enable?")) {
if (promptPW) {
$.post("/tests/full", { password: promptPW });
}
return false;
});
最后,这是Flask Route中Power State的吸气剂 -
def get_power_state():
url = 'http://' + denon_ip + status_url
try:
response = requests.get(url)
root = ElementTree.fromstring(response.content)
for value in root.iter('Power'):
powerState = value[0].text
# print("Power State - ", powerState)
except requests.exceptions.RequestException as e:
print("Network Exception - ", e)
powerState = 'N/A'
return powerState