0
약간의 REST API가 필요하고 Cherrypy를 선택했습니다. 저는 약 2 년 이래 Cherrypy RESTApi를 쓰고 있습니다. 자, 평소와 똑같은 시작을 사용하여 오류가 발생했습니다. 그것이 나를 미치게합니다. 나는 파이썬 3.5.2 및 체리 8.1.2와 우분투 16.04에있어. 코드 :Cherrypy Object not Callable - MethodDispatcher
import cherrypy
class Sotd:
exposed = True
@cherrypy.tools.json_out()
def GET(self):
return {"message": "blub"}
class RestAPI:
exposed = True
if __name__ == '__main__':
api = RestAPI()
api.sotd = Sotd()
cherrypy.tree.mount(
api,
'/api',
{
'/sotd':
{
'request.dispatcher': cherrypy.dispatch.MethodDispatcher()
}
}
)
cherrypy.server.socket_host = '0.0.0.0'
cherrypy.server.socket_port = 8080
cherrypy.engine.start()
cherrypy.engine.block()
이제 GET 통화를하고 내 JSON을 다시 돌려 받으려고합니다.
curl http://localhost:8080/api/sotd
그리고 일이 내가 cherrypy하지 호출 가능 객체에 대해이 1-2 포스트를 보았다
Traceback (most recent call last):
File "/usr/lib/python3.5/inspect.py", line 1089, in getfullargspec
sigcls=Signature)
File "/usr/lib/python3.5/inspect.py", line 2156, in _signature_from_callable
raise TypeError('{!r} is not a callable object'.format(obj))
TypeError: <__main__.Sotd object at 0x7efc1271b4a8> is not a callable object
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/cherrypy/_cpdispatch.py", line 64, in __call__
test_callable_spec(self.callable, self.args, self.kwargs)
File "/usr/local/lib/python3.5/dist-packages/cherrypy/_cpdispatch.py", line 95, in test_callable_spec
(args, varargs, varkw, defaults) = getargspec(callable)
File "/usr/local/lib/python3.5/dist-packages/cherrypy/_cpdispatch.py", line 212, in getargspec
return inspect.getfullargspec(callable)[:4]
File "/usr/lib/python3.5/inspect.py", line 1095, in getfullargspec
raise TypeError('unsupported callable') from ex
TypeError: unsupported callable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/cherrypy/_cprequest.py", line 670, in respond
response.body = self.handler()
File "/usr/local/lib/python3.5/dist-packages/cherrypy/lib/encoding.py", line 220, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/cherrypy/_cpdispatch.py", line 68, in __call__
raise x
File "/usr/local/lib/python3.5/dist-packages/cherrypy/_cpdispatch.py", line 60, in __call__
return self.callable(*self.args, **self.kwargs)
TypeError: 'Sotd' object is not callable
를 날려 -하지만 솔루션 (간단한 설정 실패가) 나를 위해 운동 didnt는 :(
을 당신의 도움에 대한감사합니다!