Heroku是否会阻止HTTP请求?

发布于 2025-02-08 10:43:57 字数 1560 浏览 3 评论 0原文

我正在尝试使用Python中的REST API中的REST API访问MySQL数据库,该REST API使用Heroku上托管的Blask制作的REST API。我在本地运行此脚本。我尝试使用PostgreSQL附加组件,但它不起作用。然后,我尝试使用其他MySQL DB主机(freesqldatabase.com),因为我认为这是AWS的问题。它仍然不起作用。我确保通过运行“ Heroku Run Python,db.Create_all()”来创建数据库。以下错误是我两次都得到的:

2022-06-19T02:31:43.193386+00:00 heroku[router]: at=info method=POST path="/waifulist" host=waifu-list-api.herokuapp.com request_id=89bb900f-1eb8-4cd1-a21e-000c2556421c fwd="99.229.226.167" dyno=web.1 connect=0ms service=1ms status=404 bytes=393 protocol=https
2022-06-19T02:31:43.193281+00:00 app[web.1]: 10.1.53.188 - - [19/Jun/2022:02:31:43 +0000] "POST /waifulist HTTP/1.1" 404 232 "-" "python-requests/2.28.0"

这是我创建API端点的方式:

if __name__ == "__main__":
    # Create database
    db.create_all()

    # Add the Resource class as an API accessible through the given endpoint (i.e. "/waifulist")
    api.add_resource(WaifuList, "/waifulist")

    # Run app
    app.run(debug=True)

我为http请求运行的确切脚本是:

import requests

# BASE = "http://127.0.0.1:5000/"
BASE = "https://waifu-list-api.herokuapp.com/"
PASSWORD = "sievers" 

# Add first waifu entry
test1 = requests.post(BASE + "waifulist", {"id": 1, "name": "Makise Kurisu", "anime": "Steins;Gate", "rank": 1, "password": PASSWORD})
print(test1.json()) # Returns 404

其他所有内容都在此回购上: https://github.com/chubbyman2/waifu-list-api

那么Heroku是否只是阻止HTTP请求?

I'm trying to access a mySQL database using the requests library in Python from a REST API I made using Flask, hosted on Heroku. I'm running this script locally. I tried using the postgresql add-on, and it didn't work. I then tried to use a different mySQL db host (freesqldatabase.com) cuz I thought it was a problem with AWS. It still didn't work. I made sure to create the database after deployment by running 'heroku run python, then db.create_all()'. The following error is what I got both times:

2022-06-19T02:31:43.193386+00:00 heroku[router]: at=info method=POST path="/waifulist" host=waifu-list-api.herokuapp.com request_id=89bb900f-1eb8-4cd1-a21e-000c2556421c fwd="99.229.226.167" dyno=web.1 connect=0ms service=1ms status=404 bytes=393 protocol=https
2022-06-19T02:31:43.193281+00:00 app[web.1]: 10.1.53.188 - - [19/Jun/2022:02:31:43 +0000] "POST /waifulist HTTP/1.1" 404 232 "-" "python-requests/2.28.0"

Here's how I created the API endpoint:

if __name__ == "__main__":
    # Create database
    db.create_all()

    # Add the Resource class as an API accessible through the given endpoint (i.e. "/waifulist")
    api.add_resource(WaifuList, "/waifulist")

    # Run app
    app.run(debug=True)

The exact script I'm running for the HTTP request is:

import requests

# BASE = "http://127.0.0.1:5000/"
BASE = "https://waifu-list-api.herokuapp.com/"
PASSWORD = "sievers" 

# Add first waifu entry
test1 = requests.post(BASE + "waifulist", {"id": 1, "name": "Makise Kurisu", "anime": "Steins;Gate", "rank": 1, "password": PASSWORD})
print(test1.json()) # Returns 404

Everything else is on this repo: https://github.com/Chubbyman2/waifu-list-api

Does Heroku simply block HTTP requests then?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假面具 2025-02-15 10:43:57

根据Topsail的答复,显然,当我实际部署了应用程序/API时,端点并没有创建。因此,我只是将这两条线移出了出来,这样:

# Create database
db.create_all()

# Add the Resource class as an API accessible through the given endpoint (i.e. "/waifulist")
api.add_resource(WaifuList, "/waifulist")

if __name__ == "__main__":
    # Run app
    app.run(debug=True)

As per topsail's reply, apparently the endpoint wasn't being created when I actually deployed my app/API. So I just moved these two lines out, like this:

# Create database
db.create_all()

# Add the Resource class as an API accessible through the given endpoint (i.e. "/waifulist")
api.add_resource(WaifuList, "/waifulist")

if __name__ == "__main__":
    # Run app
    app.run(debug=True)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文