python - 从远程 python 服务器上的 GET 请求返回结果的字段
问题描述
我在运行 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
解决方案
您应该返回一个字符串对象,而不是一个 int 对象
替换以下行:
return result
和:
return str(result)
推荐阅读
- java - 尝试在空对象引用上调用虚拟方法 'android.graphics.Bitmap android.graphics.drawable.BitmapDrawable.getBitmap()'
- python - 在 vs 代码的终端中运行 python 会给我一个语法错误,但是,手动选择代码并运行它不会给我语法错误
- machine-learning - 在 Lipschitz Continuous 上使用三次样条(平滑函数)
- python - 尝试让外部库模块第一次在 python 中工作
- javascript - 需要帮助使用 Vuex 使用 Firebase Rest API 发送 DELETE 请求
- gnupg - 安装openvpn客户端的问题
- firebase - 无法在 M1 上的 Xcode 13 上使用 Flutter Firestore 构建 iOS 应用程序
- python - 将预期对象列表提供给要实例化的类
- docker - docker-compose 和文件权限
- rust - 为什么这两个非常相似的异步 Rust 函数之一会触发线程安全错误?