【问题标题】:Have issue during curl URL for REST API used Flask url: (35) schannel: next InitializeSecurityContext failed在使用 REST API 的 curl URL 期间出现问题 Flask url: (35) schannel: next InitializeSecurityContext failed
【发布时间】:2019-05-29 07:44:08
【问题描述】:

我已经使用 Flask 为 REST API 服务器设计了 Web 应用程序

为了从前端获取 id 和 key,后端将获取信息并执行一些操作 (仅使用 POST 方法) 卷曲命令

curl -X POST -H "Content-Type:application/json" --data "{/"account_id/":/"100002/", /"access_key/":/"AKIAWDL6TY5M2INS6J7E/"}" https://192.168.172.130:443/account

但是,当我使用如下 curl 命令时:

X POST -H "Content-Type:application/json" --data "{/"account_id/":/"100002/", /"access_key/":/"AKIAWDL6TY5M2INS6J7E/"}" https://192.168.172.130 :443/账户 curl: (35) schannel: next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) - 提供给函数的令牌无效

run.py 中的代码设计

def scan_account(_account_id:str, _access_key:str):
    # building connection to db
    mySQLDB = mysqlDBConnector()
    mySQLDB.dbConnection()

    #init record log request
    _now_time = datetime.datetime.now()
    _request_info_log:str = 'Request of account id:'+str(_account_id)+' With Access Key: '+str(_access_key)+' at: '+str(_now_time)+' direction data: incoming with action type: post request'
    mySQLDB.db_log_request_insert(_request_info_log)

    # get secret key
    _AccountID: int = _account_id
    _AccessKey: str = _access_key
    _SecretKey: str =  mySQLDB.db_get_key(_AccountID,_AccessKey)

    # init boto3 session
    _aws_session = AWS_Session(_AccessKey, _SecretKey)
    _aws_session.get_credentials()

    #init running
    _worker = Worker()
    attrs = (getattr(_worker, name) for name in dir(_worker))
    methods = filter(inspect.ismethod, attrs)
    for method in methods:
        _thread_method = threading.Thread(target=method, args=(_aws_session,))
        _thread_method.start()
        _thread_method.join()

@app.route("/account/",methods=["POST"])
def account_info():
    _account_id = request.json['account_id']
    _access_key = request.json['access_key']
    #data = {'acount_id': _account_id, 'access_key': _access_key}
    scan_account(_account_id,_access_key)
    #return jsonify(data)

if __name__ == '__main__':
    app.run(debug=True,host='0.0.0.0', port='443')

【问题讨论】:

标签: python rest flask


【解决方案1】:

好吧,让我们解决一些问题,我不建议您将其用于本地开发人员以外的任何事情。请使用正确的 SSL。

确保您已正确安装 pyOpenSSL

from flask import Flask, jsonify, request, make_response

app = Flask(__name__)

@app.route("/account/",methods=["POST"])
def account_info():
    _account_id = request.json['account_id']
    _access_key = request.json['access_key']
    data = {'acount_id': _account_id, 'access_key': _access_key}
    return make_response(jsonify(data), 200)

if __name__ == '__main__':
    app.run(debug=True,host='0.0.0.0', port='433', ssl_context='adhoc')

我还修改了您的 curl 以使其更简单,这会导致问题:

curl -X POST -H "Content-Type:application/json" --data '{"account_id":"100002", "access_key":"AKIAWDL6TY5M2INS6J7E"}' https://localhost:9443/account/ --insecure

我得到以下输出:

{
  "access_key": "AKIAWDL6TY5M2INS6J7E", 
  "acount_id": "100002"
}

这就是我测试这一切的方式:

docker run --rm -it -p 9443:443 python:3.7 bash -c '
pip install flask pyOpenSSL; 
curl -s https://gist.githubusercontent.com/kingbuzzman/a955b49a318eef9e76b4bf9026cd2595/raw/sample.py > sample.py; 
python sample.py'

这里是要点来源:https://gist.github.com/kingbuzzman/a955b49a318eef9e76b4bf9026cd2595

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-27
    • 2018-05-06
    • 2012-04-15
    • 2019-03-15
    • 1970-01-01
    • 2023-03-29
    • 2021-04-02
    • 2019-10-30
    相关资源
    最近更新 更多