【问题标题】:Unable to create Apple Music JWT token无法创建 Apple Music JWT 令牌
【发布时间】:2018-06-02 18:15:18
【问题描述】:

我正在尝试生成 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.

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

我尝试在google上搜索,它提示安装的版本jwt可能存在问题,但我安装了最新版本。

【问题讨论】:

    标签: python apple-musickit


    【解决方案1】:

    我在将私钥复制粘贴到 music_token.py 时遇到了同样的错误。 但是当我这样做而不是 secret = "" 时它起作用了。

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

    【讨论】:

      猜你喜欢
      • 2018-10-27
      • 2020-06-29
      • 2017-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-03
      • 2020-10-20
      • 2021-03-18
      相关资源
      最近更新 更多