在python中如何从URL获取头的值?
我有一个有角度的UI,当用户使用google登录并通过标头发送生成的访问令牌时,它会发出API调用。API调用部分如下所示:在python中如何从URL获取头的值?,python,angular,flask,Python,Angular,Flask,我有一个有角度的UI,当用户使用google登录并通过标头发送生成的访问令牌时,它会发出API调用。API调用部分如下所示: this.http.get( `${environment.nodeURL}/api/myApiCall`, { headers: { authorization: this.accessToken} }) API是使用flask-Python3制成的。我想将访问令牌存储在API中的局部变量上。 有人能建议我如何获得价值
this.http.get(
`${environment.nodeURL}/api/myApiCall`,
{ headers: { authorization: this.accessToken}
})
API是使用flask-Python3制成的。我想将访问令牌存储在API中的局部变量上。
有人能建议我如何获得价值吗?我尝试通过以下方式获取值:
@api.route('/verify_token')
@api.response(404, 'Invalid access_token')
class UserCheck(Resource):
def get(self):
""" Checks if the access token is valid or not """
response = urllib.request.urlopen('http://localhost:5000/user/verify_token')
print("Header value is...............",response.getheader('access_token'))
我目前正在本地主机上运行UI和API。您需要修改代码,如下所示
from flask import request
@api.route('/api/myApiCall')
class UserCheck(Resource):
def get(self):
""" Checks if the access token is valid or not """
token = request.headers.get('authorization')
# write your token validation code here
所以flask的请求库可以处理这个问题
from flask import request
header = request.headers.get('header-name')
如果我试图打印头变量的类型,它会显示头变量是非类型当你尝试这个
dict(request.headers)
我尝试过这个方法,但是我知道令牌变量总是空的。我还需要检查其他内容吗?@soubhagyashoo请尝试打印(request.headers)
,看看您是否获得了标题