[设置oauth2 cookie时,双引号被附加了

问题描述 投票:1回答:1

当我尝试设置cookie时,我在Web应用程序中使用django rest框架实现oauth2:

result.set_cookie("Authorization", "Bearer "+data['access_token'])

django在开头和结尾加上双引号,让我们举个例子:

"Bearer ISQkqzBsY8rFLW91Uurxqbit5ZQRoB"

我已经尝试过将这些解决方案作为上一个问题的答案:Django cookies place double quotes around email address,但没有成功。

django开发人员中有一个令牌,他们已将其关闭为无效令牌,但我不明白为什么? https://code.djangoproject.com/ticket/19641

预先感谢。任何帮助将不胜感激。

python django oauth-2.0 django-rest-framework setcookie
1个回答
0
投票

如果您使用的是Python 2.x,则应这样做:

result.set_cookie("Authorization", unicode("Bearer "+data['access_token']))

注意,在Python 3中,unicode方法不可用,因为所有字符串都存储为unicode。

© www.soinside.com 2019 - 2024. All rights reserved.