Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
566 views
in Technique[技术] by (71.8m points)

python-3.x - 需要帮助无法获取具有API令牌的python请求(Need help unable to get python requests with API token)

Someone help me this issue.

(有人帮我解决这个问题。)

This is my code:

(这是我的代码:)

import requests

API key correct (API密钥正确)

api_key = c87cabcf1b479b807a7b3ba8xxxxxxxxxxxxxx

headers = {

'Accept': 'application/json',

'Content-Type': 'application/json',

'Authorization': 'Token token=api_key'}

Getting List of serves from this api (从此api获取服务列表)

r = requests.get('https://myserver/api/v1.1/server/', headers = headers, verify=False)

print(r.json())

print (r.status_code)

I am getting error. (我出错了。)I checked my token correct one and not expires. (我检查了我的令牌是否正确,并且没有过期。)

r.json() : {'error': {'code': 'error', 'description': 'Authentication credentials were not provided.'}}

(r.json(): {'错误':{'代码':'错误','描述':'未提供身份验证凭据。'}})

r.status_code : 401

(状态码: 401)

I missed somewhere in header.

(我错过了标题中的某处。)

Please help me on this.

(请帮我。)

  ask by Murugesan Madappan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...