当我尝试使用 Zoom API 更新用户类型(基本或许可)时遇到问题。我需要自动向一组用户授予许可证。它仅适用于第一个用户,当我尝试更新第二个用户时,我收到此错误:
Traceback (most recent call last):
File "C:\Users\dmv\Documents\ZoomLicenseProj\Test\LicenseManager.py", line 58, in <module>
conn.request("PATCH", url_update, headers=headers, body=params)
File "C:\Users\dmv\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\dmv\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1266, in _send_request
self.putrequest(method, url, **skips)
File "C:\Users\dmv\AppData\Local\Programs\Python\Python39\lib\http\client.py", line 1092, in putrequest
raise CannotSendRequest(self.__state)
http.client.CannotSendRequest: Request-sent
我无法理解为什么它只适用于第一个,然后它就崩溃了。我认为这没什么用,但我什至尝试在每次通话之间睡 2 分钟,同样的问题。这是我的代码:
import sys
import jwt
import http.client
import datetime
import json
# Go to
# Then get API Key, API Secret and insert below
api_key = 'XXX'
api_sec = 'XXXXXX'
payload = {
'iss':api_key,
'exp': datetime.datetime.now() + datetime.timedelta(hours=2)
}
jwt_encoded = str(jwt.encode(payload, api_sec), 'utf-8')
conn = http.client.HTTPSConnection("api.zoom.us")
headers = {
'authorization': "Bearer %s" % jwt_encoded,
'content-type': "application/json"
}
licensedMemberUpdate = {'type' : '2'}
baseMemberUpdate = {'type' : '1'}
conn.request("GET", "/v2/groups", headers=headers)
res = conn.getresponse()
response_string = res.read().decode('utf-8')
response_obj = json.loads(response_string)
if 'groups' in response_obj:
groups = response_obj['groups']
for group in groups:
if 'Test_LicenseManager' in group['name']:
group_id = group['id']
conn.request("GET", "/v2/groups/" + group_id + "/members", headers=headers)
res = conn.getresponse()
response_string = res.read().decode('utf-8')
members_list = json.loads(response_string)['members']
json_lic = json.dumps(licensedMemberUpdate)
json_base = json.dumps(baseMemberUpdate)
for member in members_list:
url_update = "/v2/users/%s" % member['email']
conn.request("PATCH", url_update, headers=headers, body=json_base)
#res = conn.getresponse()
#response_obj = res.status