在提交APNS通知时,我收到以下错误 - 在手动设置密钥而没有b作为我的另一个问题后发生 . 代码是:

token = jwt.encode(
{
    'iss': TEAM_ID,
    'iat': time.time()
},
secret,
algorithm= ALGORITHM,
headers={
    'alg': ALGORITHM,
    'kid': APNS_KEY_ID,
})

触发异常的代码是:

def _bytes_to_bio(self, data):
    """
    Return a _MemoryBIO namedtuple of (BIO, char*).

    The char* is the storage for the BIO and it must stay alive until the
    BIO is finished with.
    """
    data_char_p = self._ffi.new("char[]", data) #here is the exception
    bio = self._lib.BIO_new_mem_buf(
        data_char_p, len(data)
    )
    self.openssl_assert(bio != self._ffi.NULL)

    return _MemoryBIO(self._ffi.gc(bio, self._lib.BIO_free), data_char_p)

和错误:

文件“/usr/local/lib/python3.5/site-packages/jwt/api_jwt.py”,第57行,编码为json_payload,key,algorithm,headers,json_encoder文件“/ usr / local / lib / python3 . 5 / site-packages / jwt / api_jws.py“,第98行,编码密钥= alg_obj.prepare_key(密钥)文件”/usr/local/lib/python3.5/site-packages/jwt/algorithms.py“,第226行,在prepare_key中key = load_pem_public_key(key,backend = default_backend())文件“/usr/local/lib/python3.5/site-packages/cryptography/hazmat/primitives/serialization.py”,第24行,在load_pem_public_key中return backend.load_pem_public_key(data)文件“/usr/local/lib/python3.5/site-packages/cryptography/hazmat/backends/multibackend.py”,第314行,在load_pem_public_key中返回b.load_pem_public_key(data)文件“/ usr / local / lib / python3.5 / site-packages / cryptography / hazmat / backends / openssl / backend.py“,第1088行,在load_pem_public_key中mem_bio = self._bytes_to_bio(data)文件”/ usr / local / lib / python3 .5 / site-packages / cryptography / hazmat / backends / openssl / backend.py“,第490行,_byte s_to_bio data_char_p = self._ffi.new(“char []”,data)TypeError:ctype'char []'的初始化器必须是字节或列表或元组,而不是str