python - 在 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 中找不到任何这样的设置。我哪里错了?
解决方案
好吧,我必须阅读许多答案和文章才能弄清楚这一点。所以,我希望我在这里为任何未来的访问者(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)
完全一样。我又浪费了 20 分钟https://myapp.herokuapp.com/TOKEN'
。那不管用。永远记住,现在,这很容易忘记。如果您使用的软件包需要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
好吧,这可以解决新手可能面临的问题。快乐编码。谢谢。
推荐阅读
- javascript - 从 javascript 数组创建嵌套的未排序列表
- reactjs - 使用 react-testing-library 进行测试时,我可以手动触发状态更改吗?
- c# - Unity 2d 游戏不显示 3d 文本
- swift - Material Textfield 在设置错误文本时崩溃
- tensorflow - Tensorflow:每个班级的借据
- javascript - 将onselect值从菜单组件传递到另一个组件reactjs
- ios - 'MGLMapView?' 类型的值 设置 ClusterKit 时没有成员“clusterManager”
- binary - 在八进制数减法方面需要帮助
- uwp - 如何在 Prism 7.2 中使用 UWP NavigationView 的示例
- javascript - 是否可以检索与会者的预约回复?