我正在尝试从wsgi迁移我的代码,以使用asgi / channel的asyncHttpConsumer。我可以从diaglogflow获得一个http_request。然后,我可以使用send()或send_response()进行响应。我可以做类似
的事情await self.send_response(200, b'response text',
headers=[(b"Content-Type", b"text/plain"),
])
和我的heroku服务器正常将其发送出去,但是dialogflow并没有收回任何东西。我还有另一个wsgi应用程序,仅使用
from django.http import JsonResponse
...
fulfillmentText = {'fulfillmentText': "server works correctly"}
return JsonResponse(fulfillmentText, safe=False)
实际上可以正确返回dialogflow的位置。
我尝试在asgi / channel端使用JsonResponse,但它给了我一个错误,基本上是说我没有正确使用send_response。
我需要怎么做才能在asyncHttpConsumer端正确转换我的响应?
想通了。
我只需要使用]将我的字典转换为字节>
response = json.dumps(mydict).encode('utf-8')
await self.send_response(200, fulfillmentText, headers=[(b"Content-Type", b"text/plain"),])