Hi Koios1143您好:
我是jinjon,今天在瀏覽您的這篇文章後,試著在我的NB環境執行,有些問題想請教您,不知是否可以呢?
我的NB環境說明如下:
Win 11 Home中文版
Python 3.9.7
Spyder IDE 5.1.5
Line bot 設定完成
將程式碼在我的 Spyder 執行後,調整一些錯誤後(將encoding='utf-8'拿掉),在line上輸入"新竹市",linebot 會回覆 新竹市,但是輸入"天氣 新竹市"時,它就會出現下列錯誤訊息:
[2022-06-15 01:28:50,564] ERROR in app: Exception on /callback [POST]
Traceback (most recent call last):
File "C:\Users\jinjo\anaconda3\lib\site-packages\flask\app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\jinjo\anaconda3\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\jinjo\anaconda3\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\jinjo\anaconda3\lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\jinjo\anaconda3\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\jinjo\anaconda3\lib\site-packages\flask\app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "D:\PythonProject\氣候達人\weather-36h-2.py", line 27, in callback
handler.handle(body, signature)
File "C:\Users\jinjo\anaconda3\lib\site-packages\linebot\webhook.py", line 259, in handle
self.__invoke_func(func, event, payload)
File "C:\Users\jinjo\anaconda3\lib\site-packages\linebot\webhook.py", line 271, in __invoke_func
func(event)
File "D:\PythonProject\氣候達人\weather-36h-2.py", line 80, in handle_message
res = get(city)
File "D:\PythonProject\氣候達人\weather-36h-2.py", line 41, in get
res = json.load(open('card.json','r'))
FileNotFoundError: [Errno 2] No such file or directory: 'card.json'
{"destination":"Ub4f57f0b6db3e790b0871de9058bc09c","events":[{"type":"message","message":{"type":"text","id":"16261973442172","text":"天氣 新竹市"},"webhookEventId":"01G5HM5J068F875YRER6J148PA","deliveryContext":{"isRedelivery":false},"timestamp":1655227729450,"source":{"type":"user","userId":"Ubc5678016cee49e3cd2d7a332cf6da49"},"replyToken":"56314d12e09b4cf197de5b8e6abdf9cf","mode":"active"}]}
127.0.0.1 - - [15/Jun/2022 01:28:50] "POST /callback HTTP/1.1" 500 -
請問這些錯誤產生,是否我有少了什麼步驟呢? 您程式裡面的open「card.json , bubble.json」這二個檔案是要如何產生呢?
謝謝
從這篇文章來看
https://ithelp.ithome.com.tw/articles/10245154
有在他的 github 看到這 2 個檔案
可以確認一下
https://github.com/Koios1143/12th-iT-help-data/tree/master/Day12
謝謝 hokou 的提點
我剛剛也有找到了。
輸入"天氣 台東縣" 有抓到氣象局的資料,但是它顯示「linebot.exceptions.LineBotApiError: LineBotApiError: status_code=500」。
查到 有人遇到類似的問題,但是 error code 不一樣。
檢查了line 的Available APIs是有「REPLY_MESSAGE、
PUSH_MESSAGE」,Webhook URL 測試是OK,Use webhook 有ENABLE。不知道還會有什麼設定不正確造成呢?
http://www.e-happy.com.tw/indexforum.asp?bid=18385
謝謝。
runfile('D:/PythonProject/WeatherMaster/main.py', wdir='D:/PythonProject/WeatherMaster')
status_code=500,
error_response={"details": [], "message": "Internal Server Error"}
500是伺服器的問題,可能查一下自己啟動的 ip 是不是有問題,或是 ngrok 是不是換 IP 了
其他的可能要再進一步了解了