3mora2 / WPP_Whatsapp

WPP_Whatsapp aim of exporting functions from WhatsApp Web to the python, which can be used to support the creation of any interaction, such as customer service, media sending, intelligence recognition based on phrases artificial and many other things, use your imagination
MIT License
57 stars 9 forks source link

No such file or directory: '...playwright/driver/playwright.sh install chromium --dry-run' #39

Closed rubslopes closed 3 months ago

rubslopes commented 3 months ago

My code:

from WPP_Whatsapp import Create

def new_message(message):
    global client
    message = message.get('body')
    chat_id = message.get('from')

    # Extract user ID and message content
    usuario_id = message.get('chatId')['user']

    print(usuario_id, message)

    client.sendText(chat_id, "Here's what you said:" + message)

if __name__ == '__main__':

    your_session_name = "test"
    creator = Create(session=your_session_name, browser='chrome')
    client = creator.start()

    # check state of login
    if creator.state != 'CONNECTED':
        raise Exception(creator.state)

    client.sendText('mynumber', 'Ligado')

    creator.client.onMessage(new_message)

The error:

python teste2.py
Traceback (most recent call last):
  File "/Users/rubenslopes/Documents/repositorios/whatsapp/teste2.py", line 20, in <module>
    client = creator.start()
             ^^^^^^^^^^^^^^^
  File "/Users/rubenslopes/opt/miniconda3/envs/whatsapp/lib/python3.11/site-packages/WPP_Whatsapp/controllers/initializer.py", line 123, in start
    self.create_sync()
  File "/Users/rubenslopes/opt/miniconda3/envs/whatsapp/lib/python3.11/site-packages/WPP_Whatsapp/controllers/initializer.py", line 159, in create_sync
    self.ThreadsafeBrowser = ThreadsafeBrowser(user_data_dir=self.user_data_dir, **self.__kwargs)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rubenslopes/opt/miniconda3/envs/whatsapp/lib/python3.11/site-packages/WPP_Whatsapp/controllers/browser.py", line 19, in __init__
    super().__init__(no_context=no_context,
  File "/Users/rubenslopes/opt/miniconda3/envs/whatsapp/lib/python3.11/site-packages/PlaywrightSafeThread/browser/threadsafe_browser.py", line 253, in __init__
    if install and not self.check_is_install(self._browser_name):
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rubenslopes/opt/miniconda3/envs/whatsapp/lib/python3.11/site-packages/PlaywrightSafeThread/browser/threadsafe_browser.py", line 415, in check_is_install
    completed_process = subprocess.check_output(f"{driver_executable} install {browser}  --dry-run", env=env,
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rubenslopes/opt/miniconda3/envs/whatsapp/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rubenslopes/opt/miniconda3/envs/whatsapp/lib/python3.11/subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rubenslopes/opt/miniconda3/envs/whatsapp/lib/python3.11/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Users/rubenslopes/opt/miniconda3/envs/whatsapp/lib/python3.11/subprocess.py", line 1950, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/rubenslopes/opt/miniconda3/envs/whatsapp/lib/python3.11/site-packages/playwright/driver/playwright.sh install chromium  --dry-run'

I'm running WPP_Whatsapp version 0.2.2 on MacOS. I'm running it on a conda env. This also happens if I choose firefox instead of chrome.

rubslopes commented 3 months ago

Running playwright install chromium or playwright install firefox does nothing, I believe they are both installed.

rubslopes commented 3 months ago

Running playwright install chromium --dry-run returns:

playwright install firefox --dry-run
browser: firefox version 123.0
  Install location:    /Users/rubenslopes/Library/Caches/ms-playwright/firefox-1440
  Download url:        https://playwright.azureedge.net/builds/firefox/1440/firefox-mac-13-arm64.zip
  Download fallback 1: https://playwright-akamai.azureedge.net/builds/firefox/1440/firefox-mac-13-arm64.zip
  Download fallback 2: https://playwright-verizon.azureedge.net/builds/firefox/1440/firefox-mac-13-arm64.zip

Maybe it is running playwright.sh install chromium --dry-run when it should not have the .sh?

Patrickph commented 3 months ago

The same error over here, I'm investigating what it could be because this error only occurs on the Linux version. When I run the Playwright script manually, no error occurs, so the file exists, but there's some internal conflict causing this.

3mora2 commented 3 months ago

You can stop auto install creator = Create(session=your_session_name, browser='chrome'، install=False)

Patrickph commented 3 months ago

Well now the symptom has changed, logs:

Exception in thread Thread-1 (thread_worker): Traceback (most recent call last): File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner self.run() File "/usr/lib/python3.11/threading.py", line 975, in run self._target(*self._args, **self._kwargs) File "/usr/local/lib/python3.11/dist-packages/PlaywrightSafeThread/browser/threadsafe_browser.py", line 270, in __thread_worker self.loop.run_until_complete(self.start_playwright()) File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/PlaywrightSafeThread/browser/threadsafe_browser.py", line 338, in __start_playwright self.context = await self.browser_type.launch_persistent_context(**self._browser_persistent_option) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ubuntu/.local/lib/python3.11/site-packages/playwright/async_api/_generated.py", line 15075, in launch_persistent_context await self._impl_obj.launch_persistent_context( File "/home/ubuntu/.local/lib/python3.11/site-packages/playwright/_impl/_browser_type.py", line 157, in launch_persistent_context from_channel(await self._channel.send("launchPersistentContext", params)), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ File "/home/ubuntu/.local/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 63, in send return await self._connection.wrap_api_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ubuntu/.local/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 495, in wrap_api_call return await cb() ^^^^^^^^^^ File "/home/ubuntu/.local/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 101, in inner_send result = next(iter(done)).result() ^^^^^^^^^^^^^^^^^^^^^^^^^ playwright._impl._errors.Error: Executable doesn't exist at /tmp/PLAYWRIGHT_BROWSERS_PATH/firefox-1438/firefox/firefox

3mora2 commented 3 months ago

Please try check_is_install and send when work fine

3mora2 commented 3 months ago

I think path file break down, like /tmp/PLAYWRIGHT_BROWSERS_PATH/firefox-1438/firefox/firefox check if path is exist

Patrickph commented 3 months ago

There are several folders in tmp, and I believe that "PLAYWRIGHT_BROWSERS_PATH" is just a variable to be replaced to choose the specific browser for that session, as there are several folders with various browsers in /tmp/.

3mora2 commented 3 months ago

Check line i create dir and set it as playwright path

Patrickph commented 3 months ago

From what I analyzed, the code is correct, I believe there is some incompatibility with the Ubuntu version on my server, I will reset the server settings tomorrow and try to do a clean installation

rubslopes commented 3 months ago

Thank you guys for your effort into this!

I managed to find a temporary fix:

Running playwright install chromium --dry-run returns this, as I mentioned earlier:

browser: firefox version 123.0
  Install location:    /Users/rubenslopes/Library/Caches/ms-playwright/firefox-1440
  Download url:        https://playwright.azureedge.net/builds/firefox/1440/firefox-mac-13-arm64.zip
  Download fallback 1: https://playwright-akamai.azureedge.net/builds/firefox/1440/firefox-mac-13-arm64.zip
  Download fallback 2: https://playwright-verizon.azureedge.net/builds/firefox/1440/firefox-mac-13-arm64.zip

So I used the install location as the executable_path inside the Creator call:

creator = Create(session=your_session_name, browser='firefox', install=False, executable_path='/Users/rubenslopes/Library/Caches/ms-playwright/firefox-1440/firefox/Nightly.app/Contents/MacOS/firefox', headless=False)
3mora2 commented 3 months ago

temporary fix: (you don't need change executable_path with every browser)

creator = Create(session=your_session_name, browser='firefox', install=False, PLAYWRIGHT_BROWSERS_PATH='/Users/rubenslopes/Library/Caches/ms-playwright', headless=False)

OR

Update PlaywrightSafeThread pip install PlaywrightSafeThread -U and use playwright_path_env=False to not change default path

creator = Create(session=your_session_name, browser='firefox', install=False, playwright_path_env=False, headless=False)
Patrickph commented 3 months ago

now it is working 100%