【发布时间】:2021-04-29 04:30:42
【问题描述】:
我在运行 python 代码的树莓派 4 上从邮递员向我的服务器执行“GET”请求时遇到问题...
我面临的错误是:
'int' object is not callable The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a int.
此代码的工作是计算来自传感器的值流,然后返回它们的平均值,但每当我尝试它时,它总是给我这个错误.. #请注意,它在 Pycharm 上运行良好,但在请求中没有。
python 脚本是:
def oxygin():
result = "Result is: "
print("\nSparkFun MAX3010x Photodetector - Example 5\n")
sensor = qwiic_max3010x.QwiicMax3010x()
if sensor.begin() == False:
print("The Qwiic MAX3010x device isn't connected to the system. Please check your connection", \
file=sys.stderr)
return
else:
print("The Qwiic MAX3010x is connected.")
print("Place your index finger on the sensor with steady pressure.")
if sensor.setup() == False:
print("Device setup failure. Please check your connection", \
file=sys.stderr)
return
else:
print("Setup complete.")
sensor.setPulseAmplitudeRed(0x0A) # Turn Red LED to low to indicate sensor is running
sensor.setPulseAmplitudeGreen(0) # Turn off Green LED
RATE_SIZE = 4 # Increase this for more averaging. 4 is good.
rates = list(range(RATE_SIZE)) # list of heart rates
rateSpot = 0
lastBeat = 0 # Time at which the last beat occurred
beatsPerMinute = 0.00
OxiAvg = 0
samplesTaken = 0 # Counter for calculating the Hz or read rate
startTime = millis() # Used to calculate measurement rate
while True:
irValue = sensor.getIR()
samplesTaken += 1
if sensor.checkForBeat(irValue) == True:
# We sensed a beat!
#print('')
delta = ( millis() - lastBeat )
lastBeat = millis()
beatsPerMinute = 60 / (delta / 1000.0)
beatsPerMinute = round(beatsPerMinute,1)
if beatsPerMinute < 255 and beatsPerMinute > 20:
rateSpot += 1
rateSpot %= RATE_SIZE # Wrap variable
rates[rateSpot] = beatsPerMinute # Store this reading in the array
# Take average of readings
OxiAvg = 0
for x in range(0, RATE_SIZE):
OxiAvg += rates[x]
OxiAvg /= RATE_SIZE
OxiAvg = round(OxiAvg)
Hz = round(float(samplesTaken) / ( ( millis() - startTime ) / 1000.0 ) , 2)
if (samplesTaken > 1000) == 1:
result = str(OxiAvg)
#return str(OxiAvg)
#print('SpO2=', (beatAvg+15) , '%\t')
return result
【问题讨论】:
-
你能发布错误的完整回溯吗?
标签: python server get raspberry-pi