【问题标题】:Unable to get response from FreshDesk API in proxy mode {"code" : "invalid_credentials", "message" : "You need to be logged in to perform action"}无法在代理模式下从 FreshDesk API 获得响应 {"code" : "invalid_credentials", "message" : "You need to be logged in to perform action"}
【发布时间】:2021-10-27 05:31:37
【问题描述】:

所以我使用 FreshDesk API 并能够使用请求模块获取响应,但是每当我使用代理服务器时,我都无法获得响应。

import base64
import requests
import os
from requests.auth import HTTPBasicAuth
import ssl
method = "get"
url = "https://mycompanydomain.freshdesk.com/api/v2/tickets"
apiKey = "XXXXXXXXX"
secret = "x"
os.environ["REQUESTS_CA_BUNDLE"] = "Path to CA Certs"
auth = HTTPBasicAuth(apiKey, secret)
rsp = requests.request(method, url, headers=None, auth=auth)
print(rsp.text)

但是每当我在我的组织中使用代理服务器时,我都会收到一条错误消息,如 {"code":"invalid_credentials","message":"您必须登录才能执行此操作行动。”}

我用于代理服务器的代码

import base64
import requests
import http.client
import urllib.parse
method = "get"
apiKey = "XXXXXXXX"
secret = "x"
url = "https://mycompanydomain.freshdesk.com/api/v2/tickets"
cred= '{}:{}'.format(apiKey, secret)
cred =  base64.b64encode(cred.encode('utf-8')).decode('utf-8')
authorization_headers = {
        'Proxy-Authorization': 'Basic {}'.format(cred)
}
conn = http.client.HTTPSConnection("11.125.250.121", 3128)
conn.set_tunnel("mycompanydomain.freshdesk.com", headers = authorization_headers)
headers = { 'Content-Type' : 'application/json' }
conn.request("GET", "/api/v2/tickets",headers = headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

FreshDesk API 文档用于使用他们的 API

curl -v -u abcdefghij1234567890:X -H "Content-Type: application/json" -X GET 'https://domain.freshdesk.com/api/v2/tickets'

有什么办法可以解决这个错误?

【问题讨论】:

  • 确保您拥有正确的 apiKey 和密码
  • Apikey 和 secret 肯定是正确的@Sabil

标签: python python-3.x python-requests freshdesk


【解决方案1】:

这里有点猜测,我还没有真正尝试过,但我确实使用了 Freshdesk,而且我应该使用他们的 API。

这里是 Freshdesk API 的链接: https://support.freshdesk.com/support/solutions/articles/216548-create-and-update-tickets-with-custom-fields-using-api

我会尝试去掉 "-H"Content-Type: application/json" 以更好地匹配建议的代码。在大多数情况下,我会为 POSTS 而不是 GETs 添加内容类型,除非 API 专门要求它. 试试看,告诉我们它是如何工作的。

curl -u API_KEY:X -X GET https://domain.freshdesk.com/api/v2/ticket_fields

【讨论】:

  • 我用上面的方法试过了也没用。
  • 嗯。谢谢你的更新。在他们的支持下,我很幸运。试着告诉他们,你可能遇到了错误。它们不时发生。我想知道你的秘密中的特殊角色是否有问题......祝你好运
猜你喜欢
  • 2020-09-06
  • 2021-03-13
  • 2022-09-27
  • 2022-12-27
  • 1970-01-01
  • 2013-05-16
  • 1970-01-01
  • 1970-01-01
  • 2012-02-03
相关资源
最近更新 更多