seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
5k stars 942 forks source link

ValueError: not enough values to unpack (expected 5, got 4) on sb.uc_gui_handle_cf #2937

Closed moadennagi closed 1 month ago

moadennagi commented 1 month ago

Environment: Linux ubuntu 22.04 python3.10 seleniumbase==4.28.5

Steps to reproduce On a fresh install, run the following example the turnstyle example https://seleniumbase.io/help_docs/uc_mode/#uc-mode

from seleniumbase import SB

with SB(uc=True, test=True) as sb:
    url = "https://seleniumbase.io/apps/turnstile"
    sb.uc_open_with_reconnect(url, reconnect_time=2)
    sb.uc_gui_handle_cf()
    sb.assert_element("img#captcha-success", timeout=3)
    sb.set_messenger_theme(location="top_left")
    sb.post_message("SeleniumBase wasn't detected", duration=3)

I get the following error:

Using cached pillow-10.4.0-cp310-cp310-manylinux_2_28_x86_64.whl (4.5 MB)
Installing collected packages: pytweening, python3-Xlib, pyrect, pyperclip, pymsgbox, pygetwindow, Pillow, mouseinfo, pyscreeze, pyautogui
Successfully installed Pillow-10.4.0 mouseinfo-0.1.3 pyautogui-0.9.54 pygetwindow-0.0.9 pymsgbox-1.0.9 pyperclip-1.9.0 pyrect-0.2.0 pyscreeze-0.1.30 python3-Xlib-0.15 pytweening-1.2.0
Traceback (most recent call last):
  File "/home/mennagi/Documents/selenium/.venv/lib/python3.10/site-packages/seleniumbase/plugins/sb_manager.py", line 964, in SB
    yield sb
  File "/home/mennagi/Documents/selenium/turnstyle.py", line 6, in <module>
    sb.uc_gui_handle_cf()
  File "/home/mennagi/Documents/selenium/.venv/lib/python3.10/site-packages/seleniumbase/core/browser_launcher.py", line 4333, in <lambda>
    lambda *args, **kwargs: uc_gui_handle_cf(
  File "/home/mennagi/Documents/selenium/.venv/lib/python3.10/site-packages/seleniumbase/core/browser_launcher.py", line 909, in uc_gui_handle_cf
    import pyautogui
  File "/home/mennagi/Documents/selenium/.venv/lib/python3.10/site-packages/pyautogui/__init__.py", line 246, in <module>
    import mouseinfo
  File "/home/mennagi/Documents/selenium/.venv/lib/python3.10/site-packages/mouseinfo/__init__.py", line 223, in <module>
    _display = Display(os.environ['DISPLAY'])
  File "/home/mennagi/Documents/selenium/.venv/lib/python3.10/site-packages/Xlib/display.py", line 89, in __init__
    # Translations for keysyms to strings.
  File "/home/mennagi/Documents/selenium/.venv/lib/python3.10/site-packages/Xlib/display.py", line 71, in __init__
    # don't cache NONE responses in case someone creates this later
  File "/home/mennagi/Documents/selenium/.venv/lib/python3.10/site-packages/Xlib/protocol/display.py", line 84, in __init__
    self.send_active = 0
ValueError: not enough values to unpack (expected 5, got 4)

The issue only happens the first time I run the example, the example runs ok afterwards

mdmintz commented 1 month ago

I'm not able to reproduce this issue on Linux with a fresh install. Might be something else going on with your environment. Since you mentioned that it works after the first time you run the example, you may want to put in a dummy method so that the first time doesn't occur for your real scripts.