"None" is returned on the request in Python Asyncio

56 Views Asked by At

I have started learning asyncio in Python, want to fetch data from a URL. When i print the fixtures in fixtures.py and result in utils.py, i am getting "None"

FILE fixtures.py

import asyncio
from utils import fetch

class Fixture:
    def __init__(self, session):
        self.session = session

    async def get_fixture(self):
        url = "*************"
        fixtures = await fetch(self.session, url)

        print (fixtures)

FILE utils.py

import asyncio

async def fetch(session, url):
    async with session.get(url) as response:
        result = await response.json()
        print(result)
        return result

FILE main.py

import aiohttp
import asyncio
from fixtures import Fixture

async def main():
    async with aiohttp.ClientSession() as session:
        fix = Fixture(session)
        #print(fix)
        fixture = await fix.get_fixture()

asyncio.run(main())
0

There are 0 best solutions below