python属性错误: object has no attribute

标签 python python-2.7

我有一个继承自“RestHandler”的类“UserHandler”,但由于某些原因它没有正确继承,因为我不断收到“AttributeError:‘UserHandler’对象没有属性‘sendJson’”错误。我正在运行 python 2.7 顺便说一下。

下面的代码和回溯:

import json
import webapp2

class RestHandler(webapp2.RequestHandler):

  def dispatch(self):
    #time.sleep(1)
    super(RestHandler, self).dispatch()


  def SendJson(self, r):
    self.response.headers['content-type'] = 'text/plain'
    self.response.write(json.dumps(r))

class UserHandler(RestHandler):
  def post(self):
    r = json.loads(self.request.body)
    user = modelUser.InsertUser(r['email'], r['firebaseUid'], r['firebaseId'])
    r = modelUser.AsDict(user)
    self.sendJson(r)

回溯:

Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 266, in Handle
    result = handler(dict(self._environ), self._StartResponse)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1519, in __call__
    response = self._internal_error(e)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "main.py", line 25, in dispatch
    super(RestHandler, self).dispatch()
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "main.py", line 37, in post
    self.sendJson(r)
AttributeError: 'UserHandler' object has no attribute 'sendJson'

最佳答案

代码定义了SendJson(大写)。但是子类调用sendJson。 (小写)

关于python属性错误: object has no attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23485535/

相关文章:

Python - 快速文件搜索

python - 无法在 sympy 中绘制 d(e^-|t|)/dt 的傅立叶变换

python - Seaborn KDE 图 : Alpha value of the line?

python-2.7 - 如何训练caffe模型?

python - pandas dataframe 通过多索引删除行

带套接字的 Python Tic Tac Toe - 套接字问题

python - 列表列表的独特元素

python - 检查 IP 地址是否在给定范围内

python - 当将同一 DataFrame 中的一列中的值替换到另一列中时,为什么 merge_first() 会显示此行为?

python - 确定 Easy Install 中的 python 版本