[問題] LINE bot回傳數值的問題

看板Python作者 (模擬市民4)時間3年前 (2022/01/04 17:03), 3年前編輯推噓2(203)
留言5則, 2人參與, 3年前最新討論串1/1
不好意思我是Python新手 目前在做LINE bot回傳raspberry pi溫度監測數值的作業 網路上的資源大多都教直接回傳原訊息 我的是收到user傳送來的特定字元時會偵測sensor的溫度並回傳 因為不太熟 app跟functino一直想不出來 想請各位大神指點 app.py reply = event.message.text if message.count('temp'): function.temperature() temperature = function.temperature reply = temperature function.py dht = adafruit_dht.DHT(board.D17) def temperature(): temperature = dht.temperature print (temperature) return temperature ====== function.py的print是為了驗證能顯示出來結果真的可以在設備上看到溫度 但是執行時有這個錯誤不知道怎麼排除 Object of type function is not JSON serializable -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.160.231.139 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1641286987.A.4B8.html

01/04 17:06, 3年前 , 1F
回傳格式錯誤
01/04 17:06, 1F

01/04 17:06, 3年前 , 2F
你仔細檢查看看哪裡打錯了
01/04 17:06, 2F

01/04 17:07, 3年前 , 3F
有可能是 key 沒打到
01/04 17:07, 3F

01/04 18:31, 3年前 , 4F
temperature = function.temperature() # call func
01/04 18:31, 4F
感謝你們熱心提供解答及方向 後來app.py改寫如下 已經可以正常運作 留個紀錄 if message.count('temp'): function.temperature() temperature = function.temperature() line_bot_api.reply_message(event.reply_token, TextSendMessage(text="Temperature is" + str(temperature))) ※ 編輯: TheSims4 (1.160.231.44 臺灣), 01/04/2022 23:53:00

01/05 00:06, 3年前 , 5F
function.temperature()可以不用叫兩次
01/05 00:06, 5F
文章代碼(AID): #1Xr0rBIu (Python)
文章代碼(AID): #1Xr0rBIu (Python)