Я хочу загрузить файл PDF с:
async def get_file (url, папка, сессия):
filename = folder.strip('\\') + '\\' + str(datetime.datetime.now()).replace(':', '_') + '.pdf'
async with session.get(url, headers = headers) as resp:
if resp.status == 200:
f = await aiofiles.open(filename, mode='wb')
await f.write(await resp.read())
await f.close()
async def download_pdf(urls, folder):
connector = aiohttp.TCPConnector(limit=60)
semaphore = asyncio.Semaphore(10)
async with aiohttp.ClientSession() as session:
async with semaphore:
async with ClientSession(connector=connector, headers=headers) as session:
tasks = [get_file(url, folder, session) for url in urls]
result = await asyncio.gather(*tasks)
urls = ['https://www.ttzqnews.com/uploads/soft/1712/2-1G219152559.pdf']
directory = r'C:\data'
asyncio.run(download_pdf(urls, directory))
Я получил следующую ошибку.
SSL error in data received
protocol: <asyncio.sslproto.SSLProtocol object at 0x00000280B59C1CC0>
transport: <_SelectorSocketTransport closing fd=4304 read=idle write=<idle, bufsize=0>>
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\asyncio\sslproto.py", line 526, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "C:\Program Files\Python37\lib\asyncio\sslproto.py", line 189, in feed_ssldata
self._sslobj.do_handshake()
File "C:\Program Files\Python37\lib\ssl.py", line 763, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)
Я добавил файл pip.ini
, но он не может решить проблему.
Что мне делать?
Спасибо.