question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception with headless=False under WSL

See original GitHub issue

I am facing AttributeError: 'ScrapyPlaywrightDownloadHandler' object has no attribute 'browser' suddenly. I noticed that it is having trouble launching the browser. I have set ``` PLAYWRIGHT_LAUNCH_OPTIONS = { “headless”: False }

2022-04-08 23:40:35 [scrapy.utils.signal] ERROR: Error caught on signal handler: <bound method ScrapyPlaywrightDownloadHandler._engine_started of <scrapy_playwright.handler.ScrapyPlaywrightDownloadHandler object at 0x7f8c31878eb0>>
Traceback (most recent call last):
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/twisted/internet/defer.py", line 1030, in adapt
    extracted = result.result()
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/scrapy_playwright/handler.py", line 130, in _launch_browser
    self.browser = await browser_launcher(**self.launch_options)
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/playwright/async_api/_generated.py", line 11633, in launch
    await self._async(
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/playwright/_impl/_browser_type.py", line 90, in launch
    Browser, from_channel(await self._channel.send("launch", params))
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 39, in send
    return await self.inner_send(method, params, False)
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/playwright/_impl/_connection.py", line 63, in inner_send
    result = next(iter(done)).result()
playwright._impl._api_types.Error: Protocol error (Browser.enable): Browser closed.
==================== Browser output: ====================
<launching> /home/raisulrana/.cache/ms-playwright/firefox-1313/firefox/firefox -no-remote -wait-for-browser -foreground -profile /tmp/playwright_firefoxdev_profile-RtZ4kg -juggler-pipe -silent
<launched> pid=16467
[pid=16467][err] Error: no DISPLAY environment variable specified
[pid=16467] <process did exit: exitCode=1, signal=null>
[pid=16467] starting temporary directories cleanup
=========================== logs ===========================
<launching> /home/raisulrana/.cache/ms-playwright/firefox-1313/firefox/firefox -no-remote -wait-for-browser -foreground -profile /tmp/playwright_firefoxdev_profile-RtZ4kg -juggler-pipe -silent
<launched> pid=16467
[pid=16467][err] Error: no DISPLAY environment variable specified
[pid=16467] <process did exit: exitCode=1, signal=null>
[pid=16467] starting temporary directories cleanup
============================================================
2022-04-08 23:40:36 [urllib3.connectionpool] DEBUG: Starting new HTTP connection (1): www.proxy-daily.com:80
2022-04-08 23:40:37 [urllib3.connectionpool] DEBUG: http://www.proxy-daily.com:80 "GET / HTTP/1.1" 301 None
2022-04-08 23:40:37 [urllib3.connectionpool] DEBUG: Starting new HTTPS connection (1): www.proxy-daily.com:443
2022-04-08 23:40:37 [urllib3.connectionpool] DEBUG: https://www.proxy-daily.com:443 "GET / HTTP/1.1" 301 None
2022-04-08 23:40:37 [urllib3.connectionpool] DEBUG: Starting new HTTPS connection (1): proxy-daily.com:443
2022-04-08 23:40:38 [urllib3.connectionpool] DEBUG: https://proxy-daily.com:443 "GET / HTTP/1.1" 200 None
2022-04-08 23:40:38 [charset_normalizer] DEBUG: Encoding detection: utf_8 is most likely the one.
2022-04-08 23:40:38 [urllib3.connectionpool] DEBUG: Starting new HTTPS connection (1): www.us-proxy.org:443
2022-04-08 23:40:39 [urllib3.connectionpool] DEBUG: https://www.us-proxy.org:443 "GET / HTTP/1.1" 200 None
2022-04-08 23:40:39 [urllib3.connectionpool] DEBUG: Starting new HTTPS connection (1): www.sslproxies.org:443
2022-04-08 23:40:39 [urllib3.connectionpool] DEBUG: https://www.sslproxies.org:443 "GET / HTTP/1.1" 200 None
2022-04-08 23:40:39 [urllib3.connectionpool] DEBUG: Starting new HTTPS connection (1): free-proxy-list.net:443
2022-04-08 23:40:39 [urllib3.connectionpool] DEBUG: https://free-proxy-list.net:443 "GET /anonymous-proxy.html HTTP/1.1" 200 None
2022-04-08 23:40:39 [urllib3.connectionpool] DEBUG: Starting new HTTPS connection (1): free-proxy-list.net:443
2022-04-08 23:40:40 [urllib3.connectionpool] DEBUG: https://free-proxy-list.net:443 "GET /uk-proxy.html HTTP/1.1" 200 None
2022-04-08 23:40:40 [urllib3.connectionpool] DEBUG: Starting new HTTP connection (1): www.free-proxy-list.net:80
2022-04-08 23:40:40 [urllib3.connectionpool] DEBUG: http://www.free-proxy-list.net:80 "GET / HTTP/1.1" 301 None
2022-04-08 23:40:40 [urllib3.connectionpool] DEBUG: Starting new HTTPS connection (1): www.free-proxy-list.net:443
2022-04-08 23:40:40 [urllib3.connectionpool] DEBUG: https://www.free-proxy-list.net:443 "GET / HTTP/1.1" 301 None
2022-04-08 23:40:40 [urllib3.connectionpool] DEBUG: Starting new HTTP connection (1): free-proxy-list.net:80
2022-04-08 23:40:40 [urllib3.connectionpool] DEBUG: http://free-proxy-list.net:80 "GET / HTTP/1.1" 301 None
2022-04-08 23:40:40 [urllib3.connectionpool] DEBUG: Starting new HTTPS connection (1): free-proxy-list.net:443
2022-04-08 23:40:41 [urllib3.connectionpool] DEBUG: https://free-proxy-list.net:443 "GET / HTTP/1.1" 200 None
2022-04-08 23:40:41 [scrapy_proxy_pool.middlewares] WARNING: No proxies available.
2022-04-08 23:40:41 [scrapy_proxy_pool.middlewares] INFO: Try to download with host ip.
2022-04-08 23:40:41 [scrapy.core.scraper] ERROR: Error downloading <GET https://www.bbc.com>
Traceback (most recent call last):
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/twisted/internet/defer.py", line 1656, in _inlineCallbacks
    result = current_context.run(
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/twisted/python/failure.py", line 489, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/scrapy/core/downloader/middleware.py", line 49, in process_request
    return (yield download_func(request=request, spider=spider))
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/twisted/internet/defer.py", line 1030, in adapt
    extracted = result.result()
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/scrapy_playwright/handler.py", line 213, in _download_request
    page = await self._create_page(request)
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/scrapy_playwright/handler.py", line 158, in _create_page
    context = await self._create_browser_context(context_name, context_kwargs)
  File "/home/raisulrana/anaconda3/envs/scrapy/lib/python3.10/site-packages/scrapy_playwright/handler.py", line 144, in _create_browser_context
    context = await self.browser.new_context(**context_kwargs)
AttributeError: 'ScrapyPlaywrightDownloadHandler' object has no attribute 'browser'
2022-04-08 23:40:41 [scrapy.core.engine] INFO: Closing spider (finished)
2022-04-08 23:40:41 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'bans/error/builtins.AttributeError': 1,
 'downloader/exception_count': 1,
 'downloader/exception_type_count/builtins.AttributeError': 1,
 'downloader/request_bytes': 295,
 'downloader/request_count': 1,
 'downloader/request_method_count/GET': 1,
 'elapsed_time_seconds': 9.730816,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2022, 4, 8, 17, 40, 41, 489424),
 'log_count/DEBUG': 26,
 'log_count/ERROR': 3,
 'log_count/INFO': 13,
 'log_count/WARNING': 1,
 'memusage/max': 63303680,
 'memusage/startup': 63303680,
 'scheduler/dequeued': 1,
 'scheduler/dequeued/memory': 1,
 'scheduler/enqueued': 1,
 'scheduler/enqueued/memory': 1,
 'start_time': datetime.datetime(2022, 4, 8, 17, 40, 31, 758608)}
2022-04-08 23:40:41 [scrapy.core.engine] INFO: Spider closed (finished)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
elacuestacommented, Apr 9, 2022

The relevant error happens earlier, when trying to start the browser: Error: no DISPLAY environment variable specified. This means you’re probably running the spider in an environment without properly configured access to a graphics system, and this is a problem for the headless=false option that you’re using.

1reaction
elacuestacommented, Apr 12, 2022

Thanks, glad you got it working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running "google-chrome" on WSL Ubuntu as --headless --no ...
I'm running Windows 10 and I have been using an Ubuntu Linux distro under the Windows Linux Subsystem.
Read more >
Connection refused to host: 127.0.0.1 in WSL maven connector
The project builds in WSL2 Ubuntu just fine with maven. I have added the exception for idea64.exe into my outgoing windows firewall rules...
Read more >
38 How To Run Your Tests Headlessly with Xvfb
In setup we are creating an instance of the headless library and issuing a .start command (which starts Xvfb). In teardown we stop...
Read more >
End-to-end Testing Tutorial | p3-insta485-clientside
If you're running the Windows Subsystem for Linux (WSL), check your version. Selenium and headless Chrome work correctly on WSL 2, but not...
Read more >
Selenium WebDriver capabilities for running tests on ...
Default: false. consoleLogs. Required if you want to capture browser console logs at various steps in your test. Console Logs are available for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found