在python中登录Simperium无法进行身份验证

时间:2012-06-07 03:37:38

标签: python authentication simperium

我正在使用最后一个python api测试simperium:

来自simperium.core import Auth

# Global CONST
SIMPERIUM_APP_ID = "..."
SIMPERIUM_API_KEY = "..."
USER_NAME = 'test@test.com'
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

2 个答案:

答案 0 :(得分:2)

你的newUser函数中的

return auth.create('email@address.com', 'password')

应该是:

return auth.create(user, pwd)

答案 1 :(得分:0)

看起来我缩小了问题范围。

如果我使用我输入的SAME电子邮件作为应用程序的用户来控制simperium,它拒绝登录,但如果将其更改为其他任何内容,则可以正常工作(这是我更改后发布示例代码的内容。)

所以,我怀疑“sample@sample.com”,它让我们创建用户(没有返回,但在数据库中可见)但是没有使用auth。但是,将其更改为“sample@sample.net”工作正常。