【发布时间】:2021-07-18 21:03:33
【问题描述】:
我使用 python flask 创建了一个后端 api,并托管在 gcp 计算引擎上。
当我尝试使用网站 www.example.com 访问 api 并在 java 脚本中调用 fetch() 时,出现 CORS 错误
Access to fetch at 'https://{ip}/api' from origin 'https://example.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
当我拨打GET 时,电话正常,但我的POST 电话不正常,并出现上述错误
下面是失败的 POST 调用
@app.route('/api/v1/xxx', methods=['POST'])
@cross_origin(origin='localhost',headers=['Content- Type'])
def upload_file():
#some code
return "successfully"
下面是工作中的get调用
@app.route('/api/v1/xxx', methods=['GET'])
@cross_origin(origin='localhost',headers=['Content- Type'])
def signUpCheck():
#some code
return jsonify(fun())
【问题讨论】:
-
在该 python/flask 环境的日志中的服务器端,服务器在发送对该 POST 请求的响应之前记录了哪些消息?
标签: javascript python nginx flask cors