提交APNS时:TypeError:ctype'char []'的初始化程序必须是字节或列表或元组,而不是str

时间:2017-08-11 14:02:49

标签: python openssl apple-push-notifications

在提交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行,in   编码       key = alg_obj.prepare_key(key)File“/usr/local/lib/python3.5/site-packages/jwt/algorithms.py”,第226行,   在prepare_key中       key = load_pem_public_key(key,backend = default_backend())File“/usr/local/lib/python3.5/site-packages/cryptography/hazmat/primitives/serialization.py”,   第24行,在load_pem_public_key中       return backend.load_pem_public_key(data)File“/usr/local/lib/python3.5/site-packages/cryptography/hazmat/backends/multibackend.py”,   第314行,在load_pem_public_key中       return b.load_pem_public_key(data)File“/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行,在_bytes_to_bio中       data_char_p = self._ffi.new(“char []”,data)   TypeError:ctype'char []'的初始值设定项必须是字节或列表或元组,而不是str

0 个答案:

没有答案