2013-04-29 103 views
3

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

+1

向我們展示你想轉換的字符串(雖然該錯誤信息是非常自我解釋,所有你需要的十六進制數字字符串中,並沒有這樣的) 。 (您是將實際設備令牌複製到腳本中,還是使用「XXXXX XXXX ...」進行嘗試?) – geoffspear 2013-04-29 15:03:11

+0

設備令牌沒問題。我正在向我的iPhone發送第一個推送通知。錯誤發生在第一個事件之後。我將編輯該問題。 – Segev 2013-04-29 15:07:07

+3

您正在用其字節替換全局deviceToken,然後在下次嘗試通過該函數再次執行該操作。這是不可重複的。 – geoffspear 2013-04-29 15:15:40

回答

7

您的設備令牌可能不是你認爲它是。也許它有一個你看不到的換行符或其他字符。

一個簡單的測試:

>>> deviceToken = '9cdcb815 d93e11ce 52baaf6c 14e27cc8 31d5ce62 2e51ce6d f75692c2 3617cadb' 
>>> deviceToken.replace(' ','') 
'9cdcb815d93e11ce52baaf6c14e27cc831d5ce622e51ce6df75692c23617cadb' 
>>> deviceToken.replace(' ','').decode('hex') 
'\x9c\xdc\xb8\x15\xd9>\x11\xceR\xba\xafl\x14\xe2|\xc81\xd5\xceb.Q\xcem\xf7V\x92\xc26\x17\xca\xdb' 
+0

+1這個想法(我最近遇到了一些非常相似的東西),但問題在其他地方。 – Segev 2013-04-29 16:14:46

相關問題