October 26, 2024
Chicago 12, Melborne City, USA
python

Python: “an integer is required” on the statement “a=0” (and ANY other statement)


The error:

Exception has occured: TypeError
an integer is required
  File "P:\Projects\test.py", line 179, in navigate
    zero_b = 0
             ^

This happens regardless what the code in zero_b’s place is. If I try printing anything, it will give the "an interger is required" message at the string or integer I’m trying to print. No further stack trace is given.

The code:

    test_a = 0

    try:
        print("Step 1")
        WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[data-testid='read-only-address']")))
    except:
        print("Step 2")
        try:
            print("Step 3")
        except:
            print("Except hit")

    zero_b = 0

I removed the stuff inside the first except (where "step 2" is) because this error happens even when there’s just a print statment there. The Selenium WebDriver folks said it couldn’t be the call to something they’d written because that shouldn’t affect a variable assignation in a different scope

you can replace zero_b = 0 with any statement (a print like print("please hhelp me") gets exactly the same result)

The circumstances:

This ONLY occures if the debugger has hit a breakpoint anywhere before these lines of code. If the debugger hasn’t hit a breakpoint, then this error does not occur. It does not matter where the breakpoint is. Various different code in the place of the WebDriverWait line will also cause this. I’m using Python 3.12.4 64-bit, debugging in VSCode.

Video:

https://www.youtube.com/watch?v=4l1ECfiDWpM

Stuff I Tried:

See video.

I reduced code down to the simplist possible failure mode. I tried multiple statements that weren’t assigning variables, I tried checking if the value of 0 was indeed an integer. I rearranged the statements. I tested with the debugger attached and detached, I tried with the breakpoint in different places, I tried removing the stack of ‘trys’, I tried removing the breakpoint entirely (which worked but whY?)



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video