无法在代理模式下从FreshDesk API获取响应{“代码”:“无效的_凭据”,“消息”:“您需要登录才能执行操作”}

2024-06-16 13:03:32 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我使用的是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)

但是,每当我在组织中使用代理服务器时,都会收到一条错误消息,{“代码”:“无效的\u凭据”,“消息”:“您必须登录才能执行此操作”。}

我用于代理服务器的代码

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"))

用于使用其API的FreshDesk API文档

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

有什么可能的方法来解决这个错误吗


Tags: importcomauthapisecretconnrequeststickets
1条回答
网友
1楼 · 发布于 2024-06-16 13:03:32

这里有一点猜测,我实际上还没有尝试过,但我确实使用了Freshdesk,我应该使用他们的API

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

我会尝试去掉“-H”内容类型:application/json”以更好地匹配建议的代码。我会为大多数情况下无法获取的帖子添加内容类型,除非API专门调用它。尝试一下,让我们知道它是如何工作的

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

相关问题 更多 >