Parse.com用户登录 - 404错误

时间:2012-04-19 21:10:02

标签: python parse-platform

我对用户身份验证缺乏经验,特别是通过restful apis。我正在尝试使用python登录parse.com中设置的用户。以下是我的代码:

  API_LOGIN_ROOT = 'https://api.parse.com/1/login'
  params = {'username':username,'password':password}
  encodedParams = urllib.urlencode(params)

  url = API_LOGIN_ROOT + "?" + encodedParams

  request = urllib2.Request(url)

  request.add_header('Content-type', 'application/x-www-form-urlencoded')

  # we could use urllib2's authentication system, but it seems like overkill for this
  auth_header =  "Basic %s" % base64.b64encode('%s:%s' % (APPLICATION_ID, MASTER_KEY))
  request.add_header('Authorization', auth_header)
  request.add_header('X-Parse-Application-Id', APPLICATION_ID)
  request.add_header('X-Parse-REST-API-Key', MASTER_KEY)

  request.get_method = lambda: http_verb


  # TODO: add error handling for server response
  response = urllib2.urlopen(request)
  #response_body = response.read()
  #response_dict = json.loads(response_body)

这是对用于访问解析休息接口的开源库的修改。

我收到以下错误:

Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/_webapp25.py", line 703, in __call__
    handler.post(*groups)
  File "/Users/nazbot/src/PantryPal_AppEngine/fridgepal.py", line 464, in post
    url = user.login()
  File "/Users/nazbot/src/PantryPal_AppEngine/fridgepal.py", line 313, in login
    url = self._executeCall(self.username, self.password, 'GET', data)
  File "/Users/nazbot/src/PantryPal_AppEngine/fridgepal.py", line 292, in _executeCall
    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)
HTTPError: HTTP Error 404: Not Found

有人能指出我搞砸的地方吗?我不太清楚为什么我得到404而不是拒绝访问或其他问题。

2 个答案:

答案 0 :(得分:1)

确保在Parse.com上创建“User”类作为特殊用户类。添加类时,请确保将类类型更改为“用户”而不是“自定义”。一个小的用户头部图标将显示在左侧的班级名称旁边。

这让我困扰了很长时间,直到Parse团队的Matt向我展示了这个问题。

答案 1 :(得分:0)

请将API_LOGIN_ROOT = 'https://api.parse.com/1/login'更改为以下内容:API_LOGIN_ROOT = 'https://api.parse.com/1/login**/**'

我在使用PHP时遇到了同样的问题,最后添加/修复了 404 错误。