当我使用aiohttp
请求url时,程序挂起了很长时间。
async def _handle_campaign_ad(self, campaign_id, access_token):
try:
async with aiohttp.ClientSession() as session:
async with session.get(
"https://graph.facebook.com/xxxxxx&limit=100&access_token={}".format(
settings.FB_API_VERSION, campaign_id, access_token)) as response:
ret = await response.text()
print(ret)
except TimeoutError as E:
pass
2个requests
正确的答案
async def _handle_campaign_ad(self, campaign_id, access_token):
try:
with requests.get(
"https://graph.facebook.com/{}/{}/ads?fields=account_id, status,effective_status, adset, campaign, id&limit=100&access_token={}".format(
settings.FB_API_VERSION, campaign_id, access_token)) as response:
ret = response.text
print(ret)
except TimeoutError as E:
pass
为什么aiohttp请求在这种情况下不起作用?我错过了什么吗?