【问题标题】:suiteCRM API call returning 401suiteCRM API 调用返回 401
【发布时间】:2020-07-06 21:00:24
【问题描述】:

我正在尝试调用 CRM 套件 api,但它只是返回 401。

{"error":"access_denied","message":"The resource owner or authorization server denied the request.","hint":"Missing \\"Authorization\\" header"}

这就是我在 python 中调用 API 的方式

import requests
url = "https://crm.unlokdevelopment.com/api/access_token"

payload = "{"client_credentials":"client_credentials",\n"client_id":****** ",\n"client_secret":"******"}" print(payload)

headers = { 'Content-Type': 'application/vnd.api+json', 'Accept': 'application/vnd.api+json' } 

print(headers)
response = requests.request("POST", url, headers=headers, data=payload) 

print(response)
print(response.text.encode('utf8'))

请告诉我我做错了什么。我也尝试过邮递员,但没有运气。 我确认凭据正确

【问题讨论】:

    标签: python api http-status-code-401 suitecrm


    【解决方案1】:

    我可以添加两件事

    1. 在您的请求中缺少grant_type,我使用password 作为类型。
    2. 不使用此标头 application/x-www-form-urlencoded 而不是 json 类型时,我遇到了同样的问题。

    一个完整的 pythong 工作示例,我从我的失眠症(如邮递员)保存的请求中得到

    import http.client
    
    conn = http.client.HTTPSConnection("nobody.crm.cr")
    
    payload = "scope=&grant_type=password&client_id=f334234324234234-5e506c358845&client_secret=fiasdasd&username=admin&password=myPasswordIsSecure"
    
    headers = {
        'content-type': "application/x-www-form-urlencoded",
        'accept': "application/json"
        }
    
    conn.request("POST", "/Api/access_token", payload, headers)
    
    res = conn.getresponse()
    data = res.read()
    
    print(data.decode("utf-8"))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-04
      • 2019-11-05
      • 1970-01-01
      • 2017-04-22
      • 1970-01-01
      • 2013-09-01
      • 2016-06-29
      • 2017-04-04
      相关资源
      最近更新 更多