[已解决]:对具有基本身份验证的ExchangeAPI的curl GETRequest不返回任何输出

2024-05-23 20:59:00 发布

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

我正在尝试对我们的本地Exchange 2016进行API调用curl -X GET -u <username>:<password> https://exchange.domain.tld/api/v2.0/me/calendars 它应该返回JSON,其中包含关于我所有日历的信息。它在一段时间内运行良好,四个月前我开始在Python脚本中使用它

脚本应该返回当前发生的所有事件

HTTPBasicAuthUser = '<username>'
HTTPBasicAuthPass = '<password>'
postHeaders = {'Content-Type': 'application/json'}

dateTimeStr = datetime.now().strftime("%Y-%m-%dT%H:%M")
calGetURL = "https://exchange.domain.tld/api/v2.0/me/calendars/<calendarID>/calendarview?startDateTime=" + dateTimeStr + ":00&endDateTime=" + dateTimeStr + ":59"
print(calGetURL)
calGetRequest = requests.get(calGetURL, auth=HTTPBasicAuth(HTTPBasicAuthUser, HTTPBasicAuthPass)).text
print(calGetRequest)

输出的calGatURL类似于:https://exchange.domain.tld/api/v2.0/me/calendars/<calendarID>/calendarview?startDateTime=2021-04-17T19:45:00&endDateTime=2021-04-17T19:45:59

第二次打印(calGetRequest)应该返回json以及给定时间内的所有my事件。它工作了四个月,在我看来没有任何变化,只是停止了工作。交易所昨天早上得到了最新的更新,机器人在今天晚上停止了工作。 由于python脚本不再工作,我也无法在debian shell中发出upper curl命令。它什么也不返回。使用与wget相同的URL,我收到一个包含所需json内容的文件

apt-get update && apt-get full-upgrade没有帮助

我正在Windows Server 2016上运行Debian 10.9 stable和Exchange 2016 CU20(15.1.2242.4)

编辑1

对于更详细的日志,我添加了一个Apache反向代理

单个cURL命令的Apache日志输出为:

192.168.2.237 - - [24/Apr/2021:10:33:07 +0200] "GET /api/v2.0/me/calendars HTTP/1.1" 401 4450 "-" "curl/7.64.0"

单个wget命令的Apache日志输出有三个条目:

192.168.2.237 - - [24/Apr/2021:10:34:30 +0200] "GET /api/v2.0/me/calendars HTTP/1.1" 401 4476 "-" "Wget/1.20.1 (linux-gnu)"
192.168.2.237 - - [24/Apr/2021:10:34:30 +0200] "GET /api/v2.0/me/calendars HTTP/1.1" 401 660 "-" "Wget/1.20.1 (linux-gnu)"
192.168.2.237 - - [24/Apr/2021:10:34:30 +0200] "GET /api/v2.0/me/calendars HTTP/1.1" 200 2405 "-" "Wget/1.20.1 (linux-gnu)"

我看到代码401,但输入的凭据是正确的。WGET在第三次尝试中获得了它

编辑2 在Exchange IIS中禁用并重新启用Basicauth成功了

谢谢大家!! 马克斯


Tags: https脚本apijsonhttpgetexchangedomain