Я хочу использовать Python3, чтобы вызвать Apple API, и он не удался, документ API-https://developer.apple.com/documentati ... ch-devices написан. https://developer.apple.com/documentati ... i-requests. Мой тестовый код ниже. Спасибо. < /P>
from datetime import datetime, timedelta
from time import time, mktime
import jwt
import requests
key_id="xxxxxxxxx"
issuer_id="xxxxxxxxxxx"
private_key_path = "./xxxxxxxxxxxxx.p8"
dt = datetime.now() + timedelta(minutes=19)
headers = {
"alg": "ES256",
"kid": key_id,
"typ": "JWT",
}
payload = {
"iss": issuer_id,
"iat": int(time()),
"exp": int(mktime(dt.timetuple())),
"aud": "apple-developer-enterprise-v1",
}
with open(private_key_path, "rb") as fh:
signing_key = fh.read()
gen_jwt = jwt.encode(payload, signing_key, algorithm="ES256", headers=headers)
headers = {
"Authorization": f"Bearer {gen_jwt}",
"Content-Type": "application/json",
"Accept": "application/json"
}
url = f"https://mdmenrollment.apple.com/server/devices"
payload = {
"limit": 1000
}
response = requests.post(url, headers=headers, json=payload)
print(f"响应状态码: {response.status_code}")
print(f"payload: {payload}")
print(f"响应头: {response.headers}")
print(f"响应内容: {response.text}")
response.raise_for_status()
print("aa11-------------", response.json())
< /code>
и ошибка < /p>
401 Client Error: Unauthorized for url: https://mdmenrollment.apple.com/server/devices
Подробнее здесь: https://stackoverflow.com/questions/796 ... se-python3
Не удалось позвонить в API `https: // mdmenrollment.apple.com/server/devices 'Использовать Python3 ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Apple прекратила аутентификацию сеанса 2FA на https://idmsa.apple.com/appleauth/auth/signin?
Anonymous » » в форуме IOS - 0 Ответы
- 20 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как позвонить в API .NET, работающий на IIS (https: // localhost: 44320) из React Native?
Anonymous » » в форуме Android - 0 Ответы
- 14 Просмотры
-
Последнее сообщение Anonymous
-