exception

Catch an exception if no debugger is attached

Catch an exception if no debugger is attached Question: Is it possible to catch an exception in Python only if a debugger is not attached, and bypass it to the debugger otherwise? An equivalent C# code: // Entry point try { … } catch (Exception e) when (!Debugger.IsAttached) { MessageBox.Show(e); } Asked By: Dmitry Fedorkov …

Total answers: 1

Python ThreadPoolExecutor: How to evaluate what caused a timeout

Python ThreadPoolExecutor: How to evaluate what caused a timeout Question: Given the following simple method that causes a TimeoutError at some point. How can I determine what were the conditions (e.g. arguments or something else) that caused the timeout? In [82]: def f(i): …: print(i) …: if i == 2: time.sleep(1) …: return "done" …: …

Total answers: 1

Type check of user input and exclude negative numbers with exceptions

Type check of user input and exclude negative numbers with exceptions Question: I have the following method, which I use to take inputs from the user and handle it via exceptions until they fullfill the criteria. def enter_data(self, message: str, typ: type): while True: try: v = typ(input(message)) if isinstance(v, int) or isinstance(v, float) and …

Total answers: 1

Iterating through python dictionary giving unexpected behavior

Iterating through python dictionary giving unexpected behavior Question: I need to iterate through a dictionary, assigning key values from user input based on a list. If the user enters anything other than valid values from the list, an else statement or exception catches it, and re-sets the list. I then need to take the values …

Total answers: 1

Why does python-ldap code raise the Exception ldap.REFERRAL?

Why does python-ldap code raise the Exception ldap.REFERRAL? Question: I’m trying to use the python-ldap library to connect to an Active Directory Server. I’m using the code found in this link. The following code works correctly: con = ldap.initialize(uri, bytes_mode=False) con.protocol_version = ldap.VERSION3 con.set_option(ldap.OPT_REFERRALS, 0) # required for AD authentication con.simple_bind_s(bindDN, bindPW) print("Authentication success!") With …

Total answers: 1

Python ValueError is it possible to get the Incorrect Value without string parsing?

Python ValueError is it possible to get the Incorrect Value without string parsing? Question: I have this bit of code : while True: try: start = int(input("Starting number: ")) fin = int(input("Ending number: ")) amount = int(input("Count by: ")) except ValueError as verr: print(‘error : ‘, verr,’n restarting ….’) else: break I would like to …

Total answers: 4

Raise Airflow Exception to Fail Task from CURL request

Raise Airflow Exception to Fail Task from CURL request Question: I am using airflow to schedule and automate Python scripts housed on a Ubuntu server. The DAG triggers a CURL request that hits a Flask API on the same machine which actually runs the script. Here is a high level overview of the flow: Airflow …

Total answers: 1

Quick checking if element exists with Python Selenium

Quick checking if element exists with Python Selenium Question: I found this answer about checking the visibility of an element. My problem with this answer is, that it never returns "Element not found". Not only that! It take a very long time to give the error message (below). from selenium import webdriver from selenium.webdriver.common.by import …

Total answers: 2

Python: Except block capturing exception that is not listed for block

Python: Except block capturing exception that is not listed for block Question: I have a function that makes a request to AWS using boto3, and I wish to capture any exceptions and raise one of two custom errors, depending on the botocore.exceptions exception that is returned. I thought I had this working, but an except …

Total answers: 1