2012-06-07 106 views
0

我測試simperium與上次的python API:Simperium登錄無法驗證

從simperium.core進口驗證

# Global CONST 
SIMPERIUM_APP_ID = "..." 
SIMPERIUM_API_KEY = "..." 
USER_NAME = '[email protected]' 
USER_PWD = 'test' 

def newUser(user, pwd): 
    auth = Auth(SIMPERIUM_APP_ID, SIMPERIUM_API_KEY) 
    print user, pwd 
    return auth.create(user, pwd) 

def login(user, pwd): 
    auth = Auth(SIMPERIUM_APP_ID, SIMPERIUM_API_KEY) 
    print user, pwd 
    return auth.authorize(user, pwd) 

def getApi(auth_token): 
    return Api(SIMPERIUM_APP_ID, auth_token) 
print newUser(USER_NAME, USER_PWD): 
token = login(USER_NAME, USER_PWD) 
print token 
print getApi(token) 

用戶與有效的標記,但在登錄創建失敗,獲得auth.authorize

Traceback (most recent call last): File "/Users/**/Proyectos/**/testdata.py", line 22, in <module> 
    token = login(USER_NAME, USER_PWD) File "/Users/**/Proyectos/***/testdata.py", line 17, in login 
    return auth.authorize(user, pwd) File "/Library/Python/2.7/site-packages/simperium/core.py", line 59, in authorize 
    response = self._request(self.appname+'/authorize/', data) File "/Library/Python/2.7/site-packages/simperium/core.py", line 40, in 
_request 
    response = urllib2.urlopen(request) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 126, in urlopen 
    return _opener.open(url, data, timeout) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 400, in open 
    response = meth(req, response) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 513, in http_response 
    'http', request, response, code, msg, hdrs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 438, in error 
    return self._call_chain(*args) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 372, in _call_chain 
    result = func(*args) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 521, in http_error_default 
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 401: UNAUTHORIZED 

回答

0

看起來像我縮小的問題。

如果我使用SAME電子郵件作爲應用程序的用戶訂閱simperium,它會拒絕登錄,但如果將其更改爲其他任何內容,則可以工作(這是我爲更改後的樣本而更改的內容代碼)。

因此,我訂購了「[email protected]」,它讓創建用戶(不返回,但在databrowse中可見)但未通過身份驗證。但是,將其更改爲「[email protected]」可以正常工作。

+0

是的,應用程序的「所有者」已經是同一應用程序的用戶。您可以使用我們的simperium用戶名和密碼登錄。 –

2
在NEWUSER功能

return auth.create('[email protected]', 'password') 

應該是:

return auth.create(user, pwd) 
+0

準備樣品是一個錯誤。仍然糾正了相同的錯誤發生。 – mamcx

+0

現在,我得到另一個問題。當嘗試推送數據api.dashboard.post(str_to_id(chanel),{'name':'dashboard','timeStamp':time.time()})時總是得到None。但是,在stats示例中,它工作正常。 – mamcx

+0

可以發佈一個完整的代碼片段? –