簡體   English   中英

在 Heroku 上部署時電報機器人應用程序出現問題

[英]Issues with telegram bot app when deploying on Heroku

我一直在嘗試將 python 應用程序部署到 heroku。 我在應用程序鏈接頁面上不斷收到 404 not found 錯誤。 當我的代碼嘗試訪問它時,我看到了這個錯誤。 現在我已經啟用了維護模式。

2021-01-02T18:02:57.797663+00:00 heroku[router]: at=info method=GET path="/" host=abhijokebot.herokuapp.com request_id=aa8f297b-5251-40cc-ba55-897a446a14f3 fwd="106.215.49.148" dyno=web.1 connect=0ms service=4ms status=404 bytes=238 protocol=https

2021-01-02T18:02:58.205536+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=abhijokebot.herokuapp.com request_id=50704ce5-fda7-48d3-9024-b1a8c87dd15a fwd="106.215.49.148" dyno=web.1 connect=0ms service=2ms status=404 bytes=238 protocol=https

2021-01-02T18:12:42.433792+00:00 heroku[router]: at=info method=GET path="/" host=abhijokebot.herokuapp.com request_id=1ea7b738-7d8a-4a3e-91f9-28e1c74a948a fwd="54.162.178.132" dyno=web.1 connect=8ms service=4ms status=404 bytes=238 protocol=http

2021-01-02T18:18:15.610626+00:00 heroku[router]: at=info method=GET path="/robots.txt" host=abhijokebot.herokuapp.com request_id=e93624c5-d9bb-4236-82d0-44c2134fbace fwd="116.202.35.94" dyno=web.1 connect=1ms service=3ms status=404 bytes=238 protocol=http

2021-01-02T18:18:15.836002+00:00 heroku[router]: at=info method=GET path="/" host=abhijokebot.herokuapp.com request_id=cc548c62-d5a0-47ab-91e2-c7ebfc630070 fwd="116.202.35.94" dyno=web.1 connect=6ms service=16ms status=404 bytes=238 protocol=http

這是一個電報機器人,所以我不確定我應該在我的應用程序鏈接頁面上看到什么,但是,一切都表明應用程序運行成功。 我猜我沒有應用程序集的默認路徑。 我到處找,但在 Heroku 中找不到任何此類設置。 我哪里錯了?

好吧,我不得不通過許多答案和文章 go 來弄清楚這一點。 所以,我希望我在這里為任何未來的訪問者節省大量的辛勤工作(Heroku 上的新手,而不是專家)好吧,Heroku 上的任何應用程序的第一個問題是他們分配了一個端口,或者您選擇了一個默認端口。 在 99% 的情況下,這將為您解決問題。

PORT = int(os.environ.get("PORT", 13978))

只是不使用通用端口,是我的猜測。 這讓我的代碼終於上線了。 否則,我有這個。

PORT = int(os.environ.get("PORT", 5000))

現在,這僅適用於電報機器人人員。 這是截至今天的工作

updater.start_webhook(listen="0.0.0.0",
                          port=PORT,
                          url_path=TOKEN)
    updater.bot.setWebhook('https://myapp.herokuapp.com/' + TOKEN)

完全一樣。 我在https://myapp.herokuapp.com/TOKEN'上又浪費了 20 分鍾。 那不管用。 永遠記住,現在,這很容易忘記。 如果您使用需要path的包,則需要為它們設置PATHS 我在webapp中做了,不起作用。 在 Heroku>app>settings> 中設置AddBuildpack選項后,我這樣做了。 這是您需要為 selenium 添加的兩個構建包。

https://github.com/heroku/heroku-buildpack-google-chrome

https://github.com/heroku/heroku-buildpack-chromedriver

總是喜歡 cli 命令

例如,我使用selenium像這樣設置PATH

heroku config:set GOOGLE_CHROME_BIN=/app/.apt/usr/bin/google_chrome
heroku config:set CHROMEDRIVER_PATH=/app/.chromedriver/bin/chromedriver

在終端。

在 python 代碼中,這樣做。

 options1 = Options()
 options1.binary_location = os.environ.get('GOOGLE_CHROME_BIN')
 options1.add_argument("--headless")
 options1.add_argument('--no-sandbox')
 options1.add_argument('--disable-dev-shm-usage')
 driver = webdriver.Chrome(executable_path=str(os.environ.get('CHROMEDRIVER_PATH')),options=options1)

當然為此導入chrome.Options from selenium.webdriver.chrome.options import Options

好吧,這可以解決新手可能面臨的問題。 快樂編碼。 謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM