加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 无法转换为HEX – TypeError:找到非十六进制数字

发布时间:2020-12-20 11:27:07 所属栏目:Python 来源:网络整理
导读:行deviceToken = deviceToken.replace(”,”).decode(‘hex’)正在崩溃我的脚本. 这是设备令牌:(更改了一些数字) deviceToken =’9cdcb815 d93e11ce 52baaf6c 14e27cc8 31d5ce62 2e51ce6d f75692c2 3617cadb’ 第一个推送通知发送正常,所以我确定设备令牌是
行deviceToken = deviceToken.replace(”,”).decode(‘hex’)正在崩溃我的脚本.
这是设备令牌:(更改了一些数字)

deviceToken =’9cdcb815 d93e11ce 52baaf6c 14e27cc8 31d5ce62 2e51ce6d f75692c2 3617cadb’

第一个推送通知发送正常,所以我确定设备令牌是好的,但在第一个事件后,我收到此错误:

['"INBOX" (UNSEEN 12)'] 
Sent Push alert.
Got an event!
['"INBOX" (UNSEEN 13)']
Exception in thread Thread-4:Exception in thread Thread-4:
    Traceback (most recent call last):
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py",line 530,in __bootstrap_inner
        self.run()
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py",line 483,in run
        self.__target(*self.__args,**self.__kwargs)
      File "server.py",line 111,in idle
        self.dosync()
      File "server.py",line 118,in dosync
        sendPushNotification(numUnseen)
      File "server.py",line 54,in sendPushNotification
        deviceToken = deviceToken.replace(' ','').decode('hex')
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/hex_codec.py",line 42,in hex_decode
        output = binascii.a2b_hex(input)
    TypeError: Non-hexadecimal digit found

Link to the script

解决方法

您的设备令牌可能不是您认为的那样.也许它有换行或其他一些你看不到的角色.

作为一个简单的测试:

>>> deviceToken = '9cdcb815 d93e11ce 52baaf6c 14e27cc8 31d5ce62 2e51ce6d f75692c2 3617cadb'
>>> deviceToken.replace(' ','')
'9cdcb815d93e11ce52baaf6c14e27cc831d5ce622e51ce6df75692c23617cadb'
>>> deviceToken.replace(' ','').decode('hex')
'x9cxdcxb8x15xd9>x11xceRxbaxaflx14xe2|xc81xd5xceb.Qxcemxf7Vx92xc26x17xcaxdb'

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读