0

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())
shanks
  • 1
  • 1
  • Are you sure that URL returns a JSON response with data in it…? – deceze Sep 28 '20 at 07:16
  • @deceze if I `print(response)`, i get : – shanks Sep 28 '20 at 07:19
  • `'Content-Length': '0'`… Doesn't seem to be anything in it. – deceze Sep 28 '20 at 07:21
  • @deceze if I try out the same without asyncio i am getting a response: `import requests url = 'https://fantasy.premierleague.com/api/bootstrap-static/‘ r = requests.get(url) json = r.json() json.keys() ` **RESPONSE** `dict_keys(['events', 'game_settings', 'phases', 'teams', 'total_players', 'elements', 'element_stats', 'element_types'])` – shanks Sep 28 '20 at 07:36

0 Answers0