我目前正在开发一个与 Docker 化的 MySQL 数据库交互的 Flask REST API。我在尝试使用 cURL 访问 /api/create_account 端点时遇到 404 错误。奇怪的是,“/”端点的索引似乎工作正常
端点:/api/create_account 卷曲请求:
curl --location 'http://localhost:5000/api/create_account' \ --header 'Content-Type: application/json' \ --data-raw '{ "username": "new_username", "email": "[email protected]", "password": "new_password" }'
错误信息:
<!doctype html>
<html lang=en>
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
到目前为止我检查过的内容:
代码片段: /api/create_account.
@app.route('/api/create_account', methods=['POST'])
def create_account():
data = request.get_json()
username = data.get('username')
email = data.get('email')
password = data.get('password')
hashed_password = hash_password(password)
write_to_Users('unique_google_id', username, email, 'UName', '2003-03-05', 'Male', 'Sample School')
return jsonify(message='Account created successfully'), 200
Dockerfile
FROM python:3.8
EXPOSE 5000
WORKDIR /app
COPY requirements.txt /app
RUN pip install -r requirements.txt
COPY app.py /app
CMD python app.py
如果您能深入了解为什么我可能会遇到专门针对 /api/create_account 端点的 404 错误,我将不胜感激。如果您需要更多信息或代码片段,请告诉我。谢谢!
我认为您缺少
-X POST
命令的 curl
选项,如果未指定方法,curl
默认为 GET
。