Django 4.2 async views not returning expected JSON response when using AsyncHttpClient
I'm stuck on something that should probably be simple. Can someone help me understand I'm experimenting with I'm stuck on something that should probably be simple. I've been struggling with this for a few days now and could really use some help. I'm working with Django 4.2 and trying to implement an asynchronous view that fetches data from an external API using the `httpx` library. However, when I try to return a JSON response, I keep getting the following behavior: `TypeError: Object of type Response is not JSON serializable`. I've already checked that the response from the API is in JSON format. Here's a simplified version of my code: ```python import httpx from django.http import JsonResponse from django.views import View class AsyncDataView(View): async def get(self, request): async with httpx.AsyncClient() as client: response = await client.get('https://api.example.com/data') # The API response is in JSON format data = response.json() # <-- This line raises the TypeError return JsonResponse(data) ``` I've tried using `response.text` and passing that to `JsonResponse`, but that results in another behavior: `json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)`. I also looked into using `await response.json()`, but it doesn't seem to be a valid method for `httpx.Response`. Could someone guide to understand why the JSON serialization is failing here and how to properly handle the response in this async view? Thanks in advance! This is part of a larger application I'm building. I'd really appreciate any guidance on this. What's the best practice here? I'm using Python latest in this project. I'm open to any suggestions. I'm developing on Linux with Python. I'm using Python latest in this project. Is this even possible?