Heroku是否会阻止HTTP请求?
我正在尝试使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据Topsail的答复,显然,当我实际部署了应用程序/API时,端点并没有创建。因此,我只是将这两条线移出了出来,这样:
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: