为什么aiohttp请求在这种情况下不起作用?

时间:2019-04-26 09:03:19

标签: python python-asyncio aiohttp

当我使用aiohttp请求url时,程序挂起了很长时间。

  1. 没有回应
  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请求在这种情况下不起作用?我错过了什么吗?

0 个答案:

没有答案