调用Flask REST API的/api/create_account端点时出现404错误
Flask API /api/create_account 404错误排查求助
我正在开发一个对接Docker化MySQL数据库的Flask REST API,访问根路径/一切正常,但用cURL请求/api/create_account端点时始终返回404错误。
请求详情
cURL命令:
curl --location 'http://localhost:5000/api/create_account' \ --header 'Content-Type: application/json' \ --data-raw '{ "username": "new_username", "email": "new_email@example.com", "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>
已完成的排查步骤
- 确认Flask应用中已正确定义
/api/create_account的POST路由 - 修改代码后已重启Flask服务器
- 验证应用内其他端点均可正常访问
- 确认所有Docker容器处于同一网络
相关代码片段
Flask路由代码(/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错误的原因,如需更多信息或代码片段,请告知。
内容的提问来源于stack exchange,提问作者Sirben
相关产品推荐
相关产品推荐

