Getting different output for the same logic?
Was trying to learn async/await in python.
Output for first Snippet : <class 'dict'>
Output for second Snippet : <class 'list'>
Snippet 1 : without async
import urllib.request
import json
def get_response(user_url):
resp = urllib.request.urlopen(user_url).read()
resp_json = json.loads(resp)
return resp_json['results'][0]
def make_request(user_url):
json_response = get_response(user_url)
print(type(json_response))
USER_URL = 'https://randomuser.me/api'
make_request(USER_URL)
Snippet 2 : with async
import urllib.request
import json
import asyncio
async def get_response(user_url):
resp = urllib.request.urlopen(user_url).read()
resp_json = json.loads(resp)
return resp_json['results'][0]
async def make_request(user_url):
json_response = await asyncio.gather(get_response(user_url))
print(type(json_response))
USER_URL = 'https://randomuser.me/api'
asyncio.run(make_request(USER_URL))
Why are we getting different output for the same logic in code?
Expectation is to get dict data type for both.
Using Python 3.10