无法创建Apple Music JWT令牌

时间:2017-12-20 08:32:43

标签: python apple-musickit

我正在尝试生成Apple Music JWT令牌。

我有有效的keyId,teamId和.p8文件+我已经安装了最新版本的pyjwt&加密。

当我尝试执行python music_token.py时,我收到以下错误消息。

(已下载here的music_token.py脚本)

Traceback (most recent call last):
  File "music_token.py", line 33, in <module>
    token = jwt.encode(payload, secret, algorithm=alg, headers=headers)
  File "/Library/Python/2.7/site-packages/jwt/api_jwt.py", line 56, in encode
    json_payload, key, algorithm, headers, json_encoder
  File "/Library/Python/2.7/site-packages/jwt/api_jws.py", line 102, in encode
    key = alg_obj.prepare_key(key)
  File "/Library/Python/2.7/site-packages/jwt/algorithms.py", line 351, in prepare_key
    key = load_pem_private_key(key, password=None, backend=default_backend())
  File "/Library/Python/2.7/site-packages/cryptography/hazmat/primitives/serialization.py", line 20, in load_pem_private_key
    return backend.load_pem_private_key(data, password)
  File "/Library/Python/2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1015, in load_pem_private_key
    password,
  File "/Library/Python/2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1234, in _load_key
    self._handle_key_loading_error()
  File "/Library/Python/2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1292, in _handle_key_loading_error
    raise ValueError("Could not deserialize key data.")
ValueError: Could not deserialize key data.

有人可以指出我正确的方向如果我在这里做错了吗?

我尝试在谷歌搜索,但它暗示安装版本jwt可能存在问题,但我已安装最新版本。

1 个答案:

答案 0 :(得分:1)

当将私钥粘贴到music_token.py时,我遇到了同样的错误。 但是当我这样做而不是秘密=“”时它起作用了。

APNS_AUTH_KEY = './APNsAuthKey_SP7C6832EZ.p8'
f = open(APNS_AUTH_KEY)
secret = f.read()