私はtwisted.internet.defer
を私のパッケージに広く使用していますが、2日間費やしても解決できない問題が発生しました。以下は私の問題のシナリオです。Python Twisted Defer returnValue dictと互換性がありません
# all imports done and correct
class infrastructure: # line 1
@inlineCallbacks
def dict_service(self):
client = MyClient()
services = yield client.listServices() # line 5
ret = (dict(service.name, [cont.container_id for cont in service.instances]) for service in dockerServices)
returnValue(ret) # line 7
私はサービスのリストを返すクライアントに電話しています。 listServices()
戻り値の型はtwisted.internet.defer.ReturnValue
です。
class myinterface:
# has infrastructure
def init:
data = dict(
container_services=self._infrastructure.dict_service(),
)
これを実行すると私は理解できない以下のエラーが発生します。誰かが助けてくれますか?それが問題を作成returnValue
でdict
を包むため
raise TypeError(repr(o) + \" is not JSON serializable\")\nexceptions.TypeError: <DeferredWithContext at 0x4bfbb48 current result: <twisted.python.failure.Failure <type 'exceptions.NameError'>>> is not JSON serializable\n"
はそれですか?
チェックして、それを更新します。 – chaosguru
私は明示的にjson.dumpsを持っていません。スタックトレースはこのようになります。 – chaosguru
プログラム内の何かがJSONで_something_を実行している必要があります。 Twisted自体は、inlineCallbacks-decorated関数から得た値をJSONで直列化しようとしていません。 –