Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中使用POST方法的Talkdesk API_Python_Api_Post_X Www Form Urlencoded - Fatal编程技术网

python中使用POST方法的Talkdesk API

python中使用POST方法的Talkdesk API,python,api,post,x-www-form-urlencoded,Python,Api,Post,X Www Form Urlencoded,我正在尝试进入talkdesk报告API。 不管凭证是否正确,它都会给我401。 我遵循这份文件: 我有以下证件: id='XXXXXXX' secret='XXXXXXX' public_key='XXXXXXX' algorithm='XXXXXXX' private_key='XXXXXXX' key_id ='XXXXXXX' import requests consumer_key = key_id consumer_secret = secret username = &

我正在尝试进入talkdesk报告API。 不管凭证是否正确,它都会给我401。 我遵循这份文件: 我有以下证件:

id='XXXXXXX'
secret='XXXXXXX'
public_key='XXXXXXX'
algorithm='XXXXXXX'
private_key='XXXXXXX'
key_id ='XXXXXXX'
import requests
     
consumer_key = key_id
consumer_secret = secret
username = "XXXX"
password = "XXXXX"

payload = {
    'grant_type': 'password',
    'client_id': consumer_key,
    'client_secret': consumer_secret,
    'username': username,
    'password': password,
    'scope':'reports:read'
}
 
r = requests.post("https://xxx.talkdeskid.com/oauth/token",  headers={"Content-Type":"application/x-www-form-urlencoded"},    data=payload)
 
print(r.content)

不确定
password
是否是grant\u类型参数的选项。唯一提到的选项是
客户端凭据

代码如下:

import requests
import base64

signed_request = base64.b64encode(b'<client_id>:<client_secret>').decode()

payload = {
    'grant_type': 'client_credentials',
    'client_id': 'xxxx',
    'client_secret': 'xxxx',
    'username': 'xxxx',
    'password': 'xxxx',
    'scope':'reports:read'
}

response = requests.post("https://xxx.talkdeskid.com/oauth/token", headers={"Authorization": "Basic {}".format(signed_request), "Content-Type":"application/x-www-form-urlencoded"}, data=payload)

print(response.content)

导入请求
导入base64
signed_request=base64.b64encode(b':').decode()
有效载荷={
“授权类型”:“客户端凭据”,
“客户id”:“xxxx”,
“客户机密”:“xxxx”,
“用户名”:“xxxx”,
“密码”:“xxxx”,
“范围”:“报告:已读”
}
响应=请求。发布(“https://xxx.talkdeskid.com/oauth/token,标头={“授权”:“基本{}”。格式(签名请求),“内容类型”:“应用程序/x-www-form-urlencoded”},数据=有效负载)
打印(response.content)