Search code examples
pythonplaywrightplaywright-python

playwright python SSL peer certificate or SSH remote key was not OK


I get this error when trying to run:

import asyncio
from playwright.async_api import async_playwright, Playwright

async def run(playwright: Playwright):
    webkit = playwright.webkit
    browser = await webkit.launch(headless=False)
    context = await browser.new_context(ignore_https_errors=True)
    page = await context.new_page()
    await page.goto("http://minha.anem.dz/pre_inscription")
    
    await browser.close()

async def main():
    async with async_playwright() as playwright:
        await run(playwright)
asyncio.run(main())

error :

playwright._impl._errors.Error: SSL peer certificate or SSH remote key was not OK

I have solution if you need.


Solution

  • Add ignore_https_errors=True to your code like this:

    import asyncio
    from playwright.async_api import async_playwright, Playwright
    
    async def run(playwright: Playwright):
        webkit = playwright.webkit
        browser = await webkit.launch(headless=False)
        context = await browser.new_context(ignore_https_errors=True)
        page = await context.new_page()
        await page.goto("http://example.com")
        
        await browser.close()
    
    async def main():
        async with async_playwright() as playwright:
            await run(playwright)
    asyncio.run(main())