0

Following code is a boiler plate code with asyncio in python to fetch response from urls. This code works fine in mac with python 3.7 but in windows 10 with python 3.8, it doesn't reach the "in here" print statement. Any clues on why that is so and how it can be fixed in windows?

 def Initiate(list, folder_week, xmlfile, csvfile):
        bap = BAPRequest(folder_week, xmlfile, csvfile)
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        future = loop.create_future()
        future = asyncio.ensure_future(bap.run(list, True))
        loop.run_until_complete(future)
        loop.close()

async def fetch(self, url, incident, session, csv):
    async with session.get(url) as response:
        **print("in here")** 
        self.format_output(await response.read())

async def bound_fetch(self, sem, url, incident, session, csv):
    async with sem:
        return await self.fetch(url, incident, session, csv)

async def run(self, r, csv):
    url = self.conversations_url
    tasks = []
    sem = asyncio.Semaphore(1000)
    sslcontext = ssl.create_default_context(cafile=certifi.where())
    sslcontext.load_cert_chain('./cert/certificate.pem',
                       './cert/plainkey.pem')

    async with ClientSession(connector=aiohttp.TCPConnector(ssl=sslcontext, force_close=True)) as session:
        for i in r:
            # pass Semaphore and session to every GET request
            task = asyncio.ensure_future(self.bound_fetch(sem, url + str(i), i, session, csv))
            tasks.append(task)
        await asyncio.gather(*tasks, return_exceptions=True)
        await session.close()   
    return "Done"
neelmeg
  • 2,459
  • 6
  • 34
  • 46
  • 2
    Does it work on macOS with Python 3.8 or on Windows with Python 3.7? – dirn May 09 '20 at 15:06
  • Good question, when tried in Windows with Python 3.7, getting ssl error. I think fixing this would make it work in windows. Will update. – neelmeg May 09 '20 at 17:05
  • Yes, it worked in Python 3.7 of Windows 10 machine after fixing the ssl error using the answer in https://stackoverflow.com/questions/52870795/windows-python-ssl-certificate-verify-failed – neelmeg May 09 '20 at 18:24

0 Answers0