[英]GET requests to Zendesk API fail using Python 3.x with the HTTP code 401 Unauthorised
我只是在测试 Zendesk API 的功能,目的是创建一个基于票证的 Slack 应用程序,但我似乎无法通过对自己进行身份验证的简单操作。
我正在按照Zendesk 帮助台上的说明使用令牌进行身份验证和请求库,但我似乎仍然得到相同的结果
状态:401 请求有问题。 退出。
错误信息。
我目前有两个版本的 Python3 代码,每次都具有相同的 output。
通过授权 header
import requests
import base64
# Set the request parameters
url = 'https://domain.zendesk.com/api/v2/tickets.json'
user = 'email'
pwd = 'token'
# Create the basic auth header
auth = user + '/token:' + pwd
auth = auth.encode("utf-8")
auth = base64.b64encode(auth)
auth = auth.decode("utf-8")
headers = {'Authorization': 'Basic ' + auth}
# Do the HTTP get request
response = requests.get(url, headers=headers)
# Check for HTTP codes other than 200
if response.status_code != 200:
print('Status:', response.status_code, 'Problem with the request. Exiting.')
exit()
# Decode the JSON response into a dictionary and use the data
data = response.json()
print(data.text)
在 requests.get 中使用 auth 元组 function
import requests
# Set the request parameters
url = 'https://domain.zendesk.com/api/v2/tickets.json'
user = 'email' + '/token'
pwd = 'token'
# Do the HTTP get request
response = requests.get(url, auth=(user, pwd))
# Check for HTTP codes other than 200
if response.status_code != 200:
print('Status:', response.status_code, 'Problem with the request. Exiting.')
exit()
# Decode the JSON response into a dictionary and use the data
data = response.json()
print(data.text)
我也试过 cURL 似乎没有任何问题。 我的猜测是它与请求库的编码方式有关,但是,我似乎无法在任何地方找到答案。
任何帮助将非常感激。
根据文档,您需要启用密码和 email 作为身份验证
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.