代码之家  ›  专栏  ›  技术社区  ›  Ethan Koch

Python-使用Redtail API时接收响应401

  •  0
  • Ethan Koch  · 技术社区  · 6 年前

    我对使用API还很陌生,当我尝试连接到Redtail API时,总是收到一个“response 401”。

    下面是一些关于Redtail的文档: https://help.redtailtechnology.com/hc/en-us/articles/203964430-Authentication-Methods-

    这是我的密码:

    import requests
    headers = {
    'APIKey': '6C135EDF-C37C-4039-AEF3-5DFC079F9E6A',
    'Username': 'Statementone',
    'Password': 'sonedemo'
    }
    r = requests.get('https://api2.redtailtechnology.com/crm/v1/rest/', n 
    headers=headers)
    print(r)
    

    任何帮助都将不胜感激!

    1 回复  |  直到 6 年前
        1
  •  0
  •   Colton Evans    6 年前

    提供凭据时,您需要使用base64编码并指定基本身份验证类型。

    注意:文档中的演示凭据似乎不再有效。此外,您使用的URL将返回404,因为它不是有效的URL。下面带有URL的示例将拉取所有联系人。

    import requests
    import base64
    
    APIKey = '6C135EDF-C37C-4039-AEF3-5DFC079F9E6A'
    Username = 'Statementone'
    Password = 'sonedemo'
    
    token = APIKey + ':' + Username + ':' + Password
    b64Val = base64.b64encode(token)
    
    headers = {'Authorization': 'Basic %s' % b64Val}
    
    r = requests.get('https://api2.redtailtechnology.com/crm/v1/rest/contacts', headers=headers)
    print(r)