I've been trying to play with Python3.5 aiohttp and I wrote this simple wrapper function -
async def perform_async_http(self, url, method, data='', headers={}):
async with aiohttp.ClientSession() as session:
if method.lower() == 'get':
async with session.get(url, headers=headers) as response:
return response
async with session.post(url, data=data, headers=headers) as response:
return response
Then, I have the following code using this function -
http_future = self.perform_async_http(url, "post", data, headers)
res = await http_future
print(res.json())
The problem is that res.json()
or res.text()
returns a co-routine.
Accessing properties like res.status
works well, but text()
or json()
returns a co-routine from which I cannot retrieve the actual response.
I think I probably don't understand something through, but I thought that awaiting on a future should return the actual value when it's ready.
Where am I wrong?