Python Sequential asyncio

Viewed 101

I can't get my head around some of async bits. I have an async function which pulls some JSON (using aiohttp) and awaits on another and then another as follows:

    bgp_asn, source = await get_probe_data(session, probe_id)
    asn_name = await get_probe_bgp_data(session, bgp_asn)

The trouble I have is that these two are not sequential and asn_name returns None as a result of bgp_asn hasn't been received yet. What would you suggest around this problem / lack of my understanding?

Updated:

async def get_probe_bgp_data(session, bgp_asn):
    PROBE_BGP_QUERY = f"https://stat.ripe.net/data/as-overview/data.json?resource=AS{bgp_asn}"
    async with session.get(PROBE_BGP_QUERY, params=HEADER) as bgp_data:
        bgp_data_output = bgp_data.json()
        return bgp_data_output["data"]["holder"]

async def get_probe_data(session, probe_id):
PROBE_URL = f"https://atlas.ripe.net/api/v2/probes/{probe_id}"
async with session.get(PROBE_URL, params=HEADER) as probe_data:
    probe_data_output = await probe_data.json()
    return probe_data_output["asn_v4"], probe_data_output["address_v4"]

Following error is thrown:

return bgp_data_output["data"]["holder"]
TypeError: 'coroutine' object is not subscriptable
sys:1: RuntimeWarning: coroutine 'ClientResponse.json' was never awaited
sys:1: RuntimeWarning: coroutine 'get_msr_data' was never awaited

Thank you

0 Answers
Related