LoginSignup
8
3

More than 3 years have passed since last update.

Heroku openで503エラーがでた話

Last updated at Posted at 2020-12-23

初投稿です。長すぎても私が疲れてしまうのでざっくりとした文章で書いてます。読みにくいかもしれませんがご了承ください。
本記事はこちらの記事を参考にさせていただきました。

 環境

WSL2(Ubuntu-20.04 LTS)
Docker
Heroku
Line-bot-sdk=1.18.0
Flask=1.1.2

Heroku にデプロイ

前提として、

  • line developersの登録
  • Flaskとline-bot-sdkをインストール
  • Herokuに登録
  • アプリケーションの登録
  • 環境変数の設定
  • webhookの設定
  • 設定ファイルの作成

は終わっているものとして話を進めたいと思います。

変更内容を反映・デプロイ

# git add .
# git commit -am "make it better"
# git push heroku main

デプロイの確認

 # heroku open
  ▸    Error opening web browser.
  ▸    Error: Exited with code 3
  ▸
  ▸    Manually visit https://あなたのアプリケーション名.herokuapp.com/ in your browser.

chromeで「https://あなたのアプリケーション名.herokuapp.com/」を開くと、以下のような画面でアプリケーションエラーになった。
※本来ならば Hello World が表示される。
84308945cc9dcd981c2d383e42478eb7.png

heroku logs --tailをしてみて!と言われているので確認する。

# heroku logs --tail

2020-12-22T11:49:11.712077+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET 
path="/" host=あなたのアプリケーション名.herokuapp.com ...
2020-12-22T11:49:12.443226+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET p 
ath="/favicon.ico" host=あなたのアプリケーション名.herokuapp.com ...

Code=H14 、status=503とでたので対策を考える。ネットで調べると以下の方法が見つかった。

方法1

 # heroku ps:scale web=1

方法2

Herokuを再起動する

 # heroku restart --app application_name
 # heroku stack:set container

等の方法があったが失敗。その後、色々調べた結果。

 # cd `your-app-dir`
 echo "web: $(basename `pwd`)" > Procfile

を行った結果、エラー文が変わった。どうやら、「Procfile」を「Profile」としていたスペルミスのようだった:sweat_smile:
Procfile変更後のエラー文が以下である。

2020-12-22T12:38:17.494371+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=あな 
たのアプリケーション名.herokuapp.com ...
2020-12-22T12:38:18.016959+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=あ 
なたのアプリケーション名.herokuapp.com ...
2020-12-22T12:38:18.602766+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET 
path="/favicon.ico" host=あなたのアプリケーション名.herokuapp.com ...

Code=H10,status=503となっているため、再び方法1,2等を試してみたが失敗。
試行錯誤すること数時間...main.pyを眺めていた時、原因が判明。

原因は環境変数でのスペルミスだった:joy:
「SECRET」→「SELECT」

誤りのコード:

$ heroku config:set YOUR_CHANNEL_SELECT="Channel Secretの文字列" --app 自分のアプリケーション名

正しいコード:

$ heroku config:set YOUR_CHANNEL_SECRET="Channel Secretの文字列" --app 自分のアプリケーション名

環境変数が間違っていたことが判明したので、main.pyのコードの該当箇所を「SECRET」に訂正し、
Heroku.comから、
アプリケーション→Settings→Config Varsにて環境変数を手動で設定しなおすことで解決した。

スクリーンショット (322).png

無事、ブラウザ上で「Hello World」が表示された。

参考文献

https://qiita.com/shimajiri/items/cf7ccf69d184fdb2fb26
https://qiita.com/yagi_eng/items/9308b680e6ee41ab1d6d

8
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
3