即使没有更改,JSON Web令牌也不再具有“解码"属性 [英] JSON Web Token no longer has 'decode' attribute despite no changes

查看:36
本文介绍了即使没有更改,JSON Web令牌也不再具有“解码"属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个为用户提供令牌的功能,以便他们可以使用Twilio Video API访问视频聊天室.根据他们的文档,我们使用以下代码对JSON Web令牌进行解码,以向我们提供其令牌:

I have a function which provides a token for a user so they can access a video chat room using the Twilio Video API. Following their docs, we decode a JSON Web Token with the following code to give us their token:

token = AccessToken(ACCOUNT_SID, API_KEY, API_SECRET, identity=f'{request.user.email}')
token.add_grant(VideoGrant(room='My Room'))
context = {
    'token': token.to_jwt().decode()
}

这在本地完美运行,并且将其推入实时服务器后,继续在该服务器上正常运行.但是,稍后进行了几次推送,但未对此代码进行任何更改,并且突然发生了此错误(如下所示).这也与另一个错误(ascii编码错误)同时出现,我认为这可能是链接的.

This worked perfectly locally, and upon pushing it to live servers, continued to work there without fault. However, a few pushes later, with no changes to this code, and this error (below) has suddenly occurred. This also comes at the same time as another error, which is an ascii encoding error, which I believe may be linked.

奇怪的是,尽管没有对此令牌对象或函数进行任何更改,但是在解码此令牌时我们突然遇到此错误.如果有人有任何指针,将不胜感激.

It's strange that although no changes have been made to this token object, or the function, that we suddenly encounter this error with decoding this token. If anyone has any pointers, would be greatly appreciated.

推荐答案

PyJWT将 jwt.encode 的返回类型从 bytes 更改为 str : https://pyjwt.readthedocs.io/zh_CN/stable/changelog.html#jwt-encode-return-type

PyJWT changed the return type of jwt.encode from bytes to str: https://pyjwt.readthedocs.io/en/stable/changelog.html#jwt-encode-return-type

解决方案是将 PyJWT 包降级/固定为 1.7.1 或删除对 decode

Solution is to either downgrade/pin the PyJWT package to 1.7.1 or remove the call to decode

context = {
    'token': token.to_jwt()
}

这篇关于即使没有更改,JSON Web令牌也不再具有“解码"属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆