microsoft / playwright-python

Python version of the Playwright testing and automation library.

Home Page:https://playwright.dev/python/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: proxy not connect

MominIqbal-1234 opened this issue · comments

Version

playwright==1.44.0

Expected behavior

return hml page

Actual behavior

Trying to load https://google.com/ using proxy http://scraperapi:abd117ecd4dee7a96bbc4dbc7b004a08@proxy-server.scraperapi.com:8001
Error: Page.goto: net::ERR_CERT_AUTHORITY_INVALID at https://google.com/
Call log:
navigating to "https://google.com/", waiting until "load"

Additional context

from playwright.sync_api import sync_playwright

def run_with_proxy():
    url = "https://google.com/"
    proxy = {
        "server": "http://my_proxy:port",
        
    }

    with sync_playwright() as p:
        browser = p.chromium.launch(headless=False, proxy=proxy)
        context = browser.new_context()
        page = context.new_page()

        try:
            print(f"Trying to load {url} using proxy {proxy['server']}")
            page.goto(url)
            print("Page loaded successfully with proxy")

        except Exception as e:
            print(f"Error: {e}")

        finally:
            browser.close()

if __name__ == "__main__":
    run_with_proxy()

Environment

- Operating System: [Ubuntu 22.04]
- CPU: [arm64]
- Browser: [All, Chromium, Firefox, WebKit]
- Python Version: [3.12]
- Other info:

You need to follow this guide for https in order to use your proxy provider: https://docs.scraperapi.com/making-requests/proxy-port-method