日々精進

新しく学んだことを書き留めていきます

pythonからheadless chromeを実行すると「Message: unknown error: net::ERR_CONNECTION_TIMED_OUT」エラー

原因はProxyの設定がないため。Proxy環境で動かす人が少ないのか、情報が少なくて困った。。

以下のようにオプションでProxyを設定すると直った。

なお、 --proxy-server=http://domain.com:8888 のようにdns名でProxyを設定すると「ERR_NO_SUPPORTED_PROXIES」エラーが出る。ProxyはIPアドレスで指定しないとだめ。色々罠が多い。。

    options = Options()
    options.add_argument('--headless')
    options.add_argument('--remote-debugging-port=9222')
    options.add_argument('--proxy-server=xxx.xxx.xxx.xxx:8888')
    driver = webdriver.Chrome(f'{ROOT_PATH}/exlib/chromedriver.exe', options=options)

参考:

stackoverrun.com

qiita.com

detail.chiebukuro.yahoo.co.jp