獲取會話時,我收到「意外錯誤」。獲取會話的Quickblox收到「意外的簽名」錯誤
這裏是我的代碼,以獲得簽名(從this修改,因爲這些代碼是沒有一些進口,特別是hmac.new()代替HMAC(),因爲代碼不爲我工作。
import sys
import json
import time
import random
import hashlib
import hmac
import urllib
import httplib
application_id = '3427'
auth_key = 'PLYHedAmxwdvt59'
auth_secret = '*some secret key*'
nonce = str(random.randint(1, 10000))
timestamp = str(int(time.time()))
signature_raw_body = ("application_id=" + application_id + "&auth_key=" + auth_key +
"&nonce=" + nonce + "×tamp=" + timestamp)
signature = hmac.new(auth_secret, signature_raw_body, hashlib.sha1).hexdigest()
params = urllib.urlencode({'application_id': application_id,
'auth_key': auth_key,
'timestamp': timestamp, 'nonce' : nonce,
'signature' : signature})
conn = httplib.HTTPSConnection("api.quickblox.com")
conn.request("POST", "/session", params, {})
response = conn.getresponse()
print response.read()
print "signature = '%s'" % signature
輸出:
<?xml version="1.0" encoding="UTF-8"?>
<session>
<application-id type="integer">3427</application-id>
<created-at type="datetime">2013-08-04T12:19:10Z</created-at>
<device-id type="integer" nil="true"/>
<id type="integer">3552056</id>
<nonce type="integer">5855</nonce>
<token>686840081c18c7dd0e0a779c233e0d9605bcb567</token>
<ts type="integer">1375618748</ts>
<updated-at type="datetime">2013-08-04T12:19:10Z</updated-at>
<user-id type="integer" nil="true"/>
</session>
signature = 'f08b68b645184619bbe59bac217506e66a840425'
接下來,我使用curl嘗試創建一個會話:
curl -X POST -H "Content-Type: application/json" -H "QuickBlox-REST-API-Version: 0.1.0" -d '{"application_id":"3427","auth_key":"PLYHedAmxwdvt59","nonce":"33432","timestamp":"1375619372","signature":"f08b68b645184619bbe59bac217506e66a840425"}' http://api.quickblox.com/session.json
我得到這個結果: {「errors」:{「base」:[「Unexpected signature」]}}
出錯了?
代碼,並不意味着簽名生成正確嗎?以前服務器會告訴我簽名有問題(我忘了確切的措詞)。 – huggie
我看到你生成簽名的Python代碼不等於鏈接中的代碼 –
因爲鏈接中的代碼沒有運行。它缺少一些導入,並且在導入時,該hmac()Alex根本無法工作。但是,我會再看一遍。 – huggie