当我尝试设置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 2.x,则应这样做:
result.set_cookie("Authorization", unicode("Bearer "+data['access_token']))
注意,在Python 3中,unicode
方法不可用,因为所有字符串都存储为unicode。