首页 > 解决方案 > [已解决]:curl GET-Request to Exchange-API with basic auth 返回无输出

问题描述

我正在尝试对我们的本地 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。它工作了四个月,在我看来没有任何改变,它只是停止工作。交易所昨天早上得到了最新的更新,机器人在今天晚上停止了工作。由于 python 脚本不再工作,我也无法在 debian shell 中发出上层 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-Command 的 Apache-Log-Output 是:

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-Command 的 Apache-Log-Output 是三个条目:

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 就可以了。

谢谢!最大限度

标签: pythoncurlbasic-authentication

解决方案


推荐阅读