gpt4 book ai didi

flask - "Not enough segments"发送带有 Bearer Token Authorization Header (flask_restful + flask_jwt_extended) 的 GET 消息时

转载 作者:行者123 更新时间:2023-12-04 11:42:54 37 4
gpt4 key购买 nike

我在 Flask 应用程序中遇到了这个错误:

curl http://0.0.0.0:8080/ -H "Authorization: Bearer TGazPL9rf3aIftplCYDTGDc8cbTd"
{
"msg": "Not enough segments"
}

这里有一个示例:
from flask import Flask
from flask_restful import Resource, Api
from flask_jwt_extended import JWTManager, jwt_required

app = Flask(__name__)
jwt = JWTManager(app)
api = Api(app)


class HelloWorld(Resource):
@jwt_required
def get(self):
return {'hello': 'world'}


api.add_resource(HelloWorld, '/')

安慰:
 * Serving Flask app "app.py" (lazy loading)
* Environment: development
* Debug mode: on
* Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 890-265-009
127.0.0.1 - - [26/Apr/2020 02:02:32] "GET / HTTP/1.1" 422 -

我无法理解:怎么了?

其他库中已抛出异常(site-packages/jwt/api_jws.py 中的第 183 行):
  def _load(self, jwt):
if isinstance(jwt, text_type):
jwt = jwt.encode('utf-8')

if not issubclass(type(jwt), binary_type):
raise DecodeError("Invalid token type. Token must be a {0}".format(
binary_type))

try:
signing_input, crypto_segment = jwt.rsplit(b'.', 1)
header_segment, payload_segment = signing_input.split(b'.', 1)
except ValueError:
raise DecodeError('Not enough segments')

最佳答案

您尝试传入的 token ( TGazPL9rf3aIftplCYDTGDc8cbTd ) 不是有效的 JWT。一个有效的 JWT 包含三个由点分隔的段:<base64_encoded_header>.<base64_encoded_payload>.<signature> .您可以在此处阅读更多相关信息:https://jwt.io/introduction/

关于flask - "Not enough segments"发送带有 Bearer Token Authorization Header (flask_restful + flask_jwt_extended) 的 GET 消息时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61436054/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com