mysql Heroku会阻止HTTP请求吗?

j2cgzkjk  于 2023-10-15  发布在  Mysql
关注(0)|答案(1)|浏览(106)

我尝试使用Python中的requests库从我使用Flask制作的REST API访问mySQL数据库,该API托管在Heroku上。我在本地运行这个脚本。我试着使用postgresql插件,它不工作。然后,我尝试使用不同的mySQL数据库主机(freesqldatabase.com),因为我认为这是AWS的问题。但还是不管用。我确保在部署后通过运行“heroku run python,then db.create_all(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

其他的都在这个repo上:https://github.com/Chubbyman2/waifu-list-api
那么Heroku只是阻止HTTP请求吗?

czfnxgou

czfnxgou1#

根据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)

相关问题