Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Can't use uc mode with headless on google colab #2932

Answered by mdmintz
parth76 asked this question in Q&A
Discussion options

def test(path):
with SB(uc = True, headless2 = True, proxy = proxies, xvfb = True) as sb:
url = 'https://www.car.gr/classifieds/cars/?category=15001'
sb.uc_open_with_reconnect(url, reconnect_time = 10)

if detect_cf(sb):
 print('cloudflare detected!')
 sb.uc_gui_handle_cf()
`else:`
 print('cloudflare not detected!')
cookies = sb.driver.get_cookies()
cookies = get_cookie_value(cookies)
save_cookies(path, cookies, 0)

Here is the error I got

Exception Traceback (most recent call last)
in <cell line: 175>()
173 make_requests(path, s)
174
--> 175 main()
176
177

5 frames
in main()
169 path = get_path()
170 print('Started!')
--> 171 test(path)
172 s = requests.Session()
173 make_requests(path, s)

in test(path)
39 if detect_cf(sb):
40 print('cloudflare detected!')
---> 41 sb.uc_gui_handle_cf()
42
43 else:

/usr/local/lib/python3.10/dist-packages/seleniumbase/core/browser_launcher.py in (*args, **kwargs)
4331 )
4332 driver.uc_gui_handle_cf = (
-> 4333 lambda *args, **kwargs: uc_gui_handle_cf(
4334 driver, *args, **kwargs
4335 )

/usr/local/lib/python3.10/dist-packages/seleniumbase/core/browser_launcher.py in uc_gui_handle_cf(driver, frame)
906 if not _on_a_cf_turnstile_page(driver):
907 return
--> 908 install_pyautogui_if_missing(driver)
909 import pyautogui
910 pyautogui = get_configured_pyautogui(pyautogui)

/usr/local/lib/python3.10/dist-packages/seleniumbase/core/browser_launcher.py in install_pyautogui_if_missing(driver)
565
566 def install_pyautogui_if_missing(driver):
--> 567 verify_pyautogui_has_a_headed_browser(driver)
568 pip_find_lock = fasteners.InterProcessLock(
569 constants.PipInstall.FINDLOCK

/usr/local/lib/python3.10/dist-packages/seleniumbase/core/browser_launcher.py in verify_pyautogui_has_a_headed_browser(driver)
559 focus on the correct element when performing actions."""
560 if hasattr(driver, "_is_hidden") and driver._is_hidden:
--> 561 raise Exception(
562 "PyAutoGUI can't be used in headless mode!"
563 )

Exception: PyAutoGUI can't be used in headless mode!

You must be logged in to vote

That's why it says: Exception: PyAutoGUI can't be used in headless mode!

Don't use UC Mode with Headless Mode.

Replies: 2 comments 11 replies

Comment options

That's why it says: Exception: PyAutoGUI can't be used in headless mode!

Don't use UC Mode with Headless Mode.

You must be logged in to vote
8 replies
Comment options

Not sure what you're doing, but I can't reproduce this. Try the existing examples.

Comment options

That's why it says: Exception: PyAutoGUI can't be used in headless mode!

Don't use UC Mode with Headless Mode.

As of now, the only way to bypass cloudflare click is with PyautoGUI right?

Comment options

Correct. PyAutoGUI is required for clicking CAPTCHAs now.

Comment options

when I use only with SB(uc=True)

I get this error

'Started!

PyAutoGUI is required for UC Mode on Linux! Installing now...

ValueError Traceback (most recent call last) /usr/local/lib/python3.10/dist-packages/seleniumbase/fixtures/base_case.py in __activate_virtual_display_as_needed(self) 13817 try:

13818 import pyautogui
13819 try:

16 frames /usr/local/lib/python3.10/dist-packages/pyautogui/init.py in 245 try: --> 246 import mouseinfo 247

/usr/local/lib/python3.10/dist-packages/mouseinfo/init.py in 222 --> 223 _display = Display(os.environ['DISPLAY']) 224

/usr/local/lib/python3.10/dist-packages/Xlib/display.py in init(self, display) 88 ---> 89 # Translations for keysyms to strings. 90 self.keysym_translations = {}

/usr/local/lib/python3.10/dist-packages/Xlib/display.py in init(self, *args, **keys) 70 ---> 71 # don't cache NONE responses in case someone creates this later 72 if r.atom != X.NONE:

/usr/local/lib/python3.10/dist-packages/Xlib/protocol/display.py in init(self, display) 83 self.send_recv_lock = lock.allocate_lock() ---> 84 self.send_active = 0 85 self.recv_active = 0

ValueError: not enough values to unpack (expected 5, got 4)

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last) in <cell line: 175>() 173 #make_requests(path, s) 174 --> 175 main() 176 177

in main() 169 path = get_path() 170 print('Started!') --> 171 test(path) 172 #s = requests.Session() 173 #make_requests(path, s)

in test(path) 32 def test(path): 33 #path = 'C:/Users/HP/Downloads/Desktop/' ---> 34 with SB(uc = True) as sb: 35 #url = 'https://www.skroutz.gr/shop/22969/Fotistikaonline/products.html' 36 url = 'https://www.car.gr/classifieds/cars/?category=15001'

/usr/lib/python3.10/contextlib.py in enter(self) 133 del self.args, self.kwds, self.func 134 try: --> 135 return next(self.gen) 136 except StopIteration: 137 raise RuntimeError("generator didn't yield") from None

/usr/local/lib/python3.10/dist-packages/seleniumbase/plugins/sb_manager.py in SB(test, rtf, raise_test_failure, browser, headless, headless2, locale_code, protocol, servername, port, proxy, proxy_bypass_list, proxy_pac_url, multi_proxy, agent, cap_file, cap_string, recorder_ext, disable_js, disable_csp, enable_ws, enable_sync, use_auto_ext, undetectable, uc_cdp_events, uc_subprocess, log_cdp_events, incognito, guest_mode, dark_mode, devtools, remote_debug, enable_3d_apis, swiftshader, ad_block_on, host_resolver_rules, block_images, do_not_track, chromium_arg, firefox_arg, firefox_pref, user_data_dir, extension_zip, extension_dir, disable_features, binary_location, driver_version, skip_js_waits, use_wire, external_pdf, is_mobile, mobile, device_metrics, xvfb, start_page, rec_print, rec_behave, record_sleep, data, var1, var2, var3, variables, account, environment, headed, maximize, disable_ws, disable_beforeunload, settings_file, uc, undetected, uc_cdp, uc_sub, log_cdp, ad_block, server, guest, wire, pls, sjw, save_screenshot, no_screenshot, page_load_strategy, timeout_multiplier, js_checking_on, slow, demo, demo_sleep, message_duration, highlights, interval, time_limit) 953 proxy_helper.remove_proxy_zip_if_present() 954 start_time = time.time() --> 955 sb.setUp() 956 test_passed = True # This can change later 957 teardown_exception = None

/usr/local/lib/python3.10/dist-packages/seleniumbase/fixtures/base_case.py in setUp(self, masterqa_mode) 14726 else: 14727 # Pure Python run. Eg. SB() Manager

14728 self.__activate_virtual_display_as_needed()
14729
14730 # Verify SeleniumBase is installed successfully, and used correctly

/usr/local/lib/python3.10/dist-packages/seleniumbase/fixtures/base_case.py in __activate_virtual_display_as_needed(self) 13837 "pyautogui", version=constants.PyAutoGUI.VER 13838 )

13839 import pyautogui
13840 pyautogui_is_installed = True
13841 if (

/usr/local/lib/python3.10/dist-packages/pyautogui/init.py in 244 245 try: --> 246 import mouseinfo 247 248 def mouseInfo():

/usr/local/lib/python3.10/dist-packages/mouseinfo/init.py in 221 raise 222 --> 223 _display = Display(os.environ['DISPLAY']) 224 225 def _linuxPosition():

/usr/local/lib/python3.10/dist-packages/Xlib/display.py in init(self, display) 87 - self.display.info.min_keycode + 1)) 88 ---> 89 # Translations for keysyms to strings. 90 self.keysym_translations = {} 91

/usr/local/lib/python3.10/dist-packages/Xlib/display.py in init(self, *args, **keys) 69 r = request.InternAtom(display = self, name = atomname, only_if_exists = only_if_exists) 70 ---> 71 # don't cache NONE responses in case someone creates this later 72 if r.atom != X.NONE: 73 self._atom_cache[atomname] = r.atom

/usr/local/lib/python3.10/dist-packages/Xlib/protocol/display.py in init(self, display) 82 # for a detailed explanation 83 self.send_recv_lock = lock.allocate_lock() ---> 84 self.send_active = 0 85 self.recv_active = 0 86

ValueError: not enough values to unpack (expected 5, got 4)'

I'm getting the same issue have you fixed that issue if yes please let me know

Comment options

You can try #2937 (comment) for the ValueError: not enough values to unpack (expected 5, got 4).

Answer selected by mdmintz
Comment options

is there a way to bypass cloudflare with headless=True?

You must be logged in to vote
3 replies
Comment options

Headless Mode isn't needed because there's Xvfb to run on GUI-less machines.

Comment options

@mdmintz Thanks man! can you please share a minimal code contains CF bypass? sorry

Comment options

from seleniumbase import SB
with SB(uc=True, test=True, xvfb=True) as sb:
 sb.activate_cdp_mode(URL)
 sb.sleep(2)
 sb.uc_gui_click_captcha()
 sb.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /