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

KeyError: ('Inspector.detached',) #3542

IndrajeethY started this conversation in General
Discussion options

- KeyError: ('Inspector.detached',) during parsing of json from event : {'method': 'I
nspector.detached', 'params': {'reason': 'target_closed'}}
Traceback (most recent call last):
 File "C:\Users\hellx\AppData\Roaming\Python\Python313\site-packages\seleniumbase\undetected\cdp_driver\connection.
py", line 581, in listener_loop
 event = cdp.util.parse_json_event(message)
 File "C:\Users\hellx\AppData\Roaming\Python\Python313\site-packages\mycdp\util.py", line 19, in parse_json_event
 return _event_parsers[json["method"]].from_json(json["params"])
 ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'Inspector.detached'

this is my error, the error is not my issue but how do i handle this error? i put the whole code in a try and except block still cant handle this out

 def launch(self, username, password):
 attempt = 0
 while attempt < self.retries and not self.stop_flag:
 try:
 with SB(uc=True, pls="none") as sb:
 logger.info(f"Trying to login with {username}")
 sb.activate_cdp_mode(self.url)
 sb.uc_gui_click_captcha()
 sb.send_keys(
 "input[name='name']", username, timeout=10
 )
 sb.send_keys(
 "input[name='password']", password, timeout=10
 )
 sb.wait_for_element_visible("div#captcha-image", timeout=10)
 screenshot_name = f"captcha_{uuid.uuid4()}.png"
 if sb.is_element_visible("div#captcha-image"):
 sleep(2)
 captcha_image = sb.get_element("div#captcha-image")
 captcha_image.save_screenshot(screenshot_name)
 logger.info(f"Screenshot saved: {screenshot_name}")
 captcha_solution = self.solve_captcha_truecaptcha(screenshot_name)
 logger.info(f"Solving math equation: {captcha_solution} for {username}")
 if captcha_solution:
 try:
 captcha_solution = captcha_solution.replace(' ', '')
 captcha_solution = str(eval(captcha_solution))
 logger.info(f"Solved CAPTCHA equation: {captcha_solution}")
 except Exception as e:
 logger.error(f"Error solving CAPTCHA equation: {e}")
 continue
 else:
 continue
 sb.send_keys(
 "input[name='captcha_code']", captcha_solution
 )
 logger.info(f"Filled in the login form for {username}")
 sb.click('button[type="submit"]')
 logger.info(
 f"Login form submitted. Waiting for response for {username}"
 )
 sb.sleep(3)
 if sb.is_element_visible('div.toastify.bg-danger'):
 error_text = sb.get_text('div.toastify.bg-danger')
 if "invalid login" in error_text.lower():
 logger.info(f"skipping {username} due to invalid login")
 return None
 else:
 logger.info(f"Retrying captcha for {username}") 
 continue
 else:
 logger.info(f"skipping {username} due to balance not found")
 return None
 except Exception as e:
 attempt += 1
 logger.info(f"Attempt {attempt} failed: {e}")
 sleep(2)
 logger.info(f"All {self.retries} attempts failed for {self.url}")
You must be logged in to vote

Replies: 1 comment 4 replies

Comment options

It would be helpful to know which line of actual script code led to your issue (from your launch method).
And what do you mean by "the error is not my issue" - "but how do i handle this error" ?

You must be logged in to vote
4 replies
Comment options

i mean ig ik coz of the error it occurs when i close my remote desktop screen, i just wanted to handle that error,

def process_credentials(self):
 with open(self.filtered_credentials_file, "r", encoding="utf-8", errors="replace") as file:
 lines = file.readlines()
 start_line = int(input("Enter start line (default 0): ") or 0)
 end_line = int(input("Enter end line (default last line): ") or len(lines))
 for line in lines[start_line:end_line]:
 parts = line.strip().split(":")
 if len(parts) < 2:
 logger.warning(f"Ignoring invalid line: {line.strip()}")
 continue
 username, password = parts[0], parts[1]
 self.launch(username, password)
 logger.info(
 f"Processing complete. Valid credentials saved to {self.valid_credentials_file}"
 )
 if __name__ == "__main__":
 try:
 credentials_file = (
 input("Enter credentials file (default 'credentials.txt'): ")
 or "credentials.txt"
 )
 filtered_credentials_file = (
 input("Enter filtered credentials file (default 'filtered_credentials.txt'): ")
 or "filtered_credentials.txt"
 )
 valid_credentials_file = (
 input("Enter valid credentials file (default 'valid_credentials.txt'): ")
 or "valid_credentials.txt"
 )
 automation = MyCls(
 credentials_file,
 filtered_credentials_file,
 valid_credentials_file,
 )
 automation.filter_credentials()
 automation.process_credentials()
 except KeyboardInterrupt:
 logger.info("KeyboardInterrupt: Exiting...")
 os._exit(0)
 os._exit(0)

and this is how i launch that func?

image

also how do i handle this case where the page doesnt load and script holds on it?

Comment options

Remote Desktop connections are not supported. See #3213 (comment).
If you still insist on using Report Desktop, then you'll need to debug that on your own.

Comment options

yeah i get it, i am not asking about issue with remote desktop, i am just asking how do i except that error? like try and except block cant catch that error also about page not available why script holds or not loads or returns any error on cdp mode?

Comment options

try:
 ## code block
except Exception:
 ## code block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

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