0

I have a rather strange error in the following code:

CUSTOMER_ORDER = ["Some", "Customers"]
ticket_types = ["analysis_tickets"] # is list because copied from legacy code and only need 1 type here (TODO replace with str.)

[...]

# Get all  tickets of each type for each customer of the month
for customer in CUSTOMER_ORDER:
    all_tickets[customer] = {}

    for ticket_type in ticket_types:
        logger.info("Getting '" + ticket_type + "' for customer " + customer + "...")

        if ticket_type == "analysis_tickets":
            suffix = ANALYSIS_TICKETS_SUFFIX
        elif ticket_type == "support_tickets":
            suffix = SUPPORT_TICKETS_SUFFIX
        elif ticket_type == "engineering_tickets":
            suffix = ENGINEERING_TICKETS_SUFFIX

        all_tickets[customer][ticket_type] = {}
        all_tickets[customer][ticket_type]["tickets"] = []

        try:
            response = requests.get(
                OTRS_URL + "/TicketSearch",
                params={
                    "UserLogin": OTRS_USER,
                    "Password": OTRS_PW,
                    "Queues": customer + suffix,
                    time_older: datetime.datetime.now(),
                    time_newer: datetime.datetime.now() - datetime.timedelta(days=TIME_RANGE_DAYS),
                    "Limit": 3000,
                },
                verify=False,
            )
            if response.status_code != 200:
                logger.error("Could not get tickets for customer " + customer + ". Error: " + str(response.status_code))
                sys.exit(1)

            if "TicketID" not in response.json():
                logger.warning("No tickets found for customer " + customer + " amd ticket type '" + ticket_type + "'.")
                all_tickets[customer][ticket_type]["tickets"] = []
            else:
                all_tickets[customer][ticket_type]["tickets"] = response.json()["TicketID"]
                logger.info("Found " + str(len(all_tickets[customer][ticket_type]["tickets"])) + " tickets for customer " + customer + " and ticket type '" + ticket_type + "'.")
                ticket_count += len(all_tickets[customer][ticket_type]["tickets"])

            # print(ticket_type + " " + ticket_types)
        except Exception as e:
            logger.error("Could not get tickets for customer " + customer + ". Error: " + traceback.format_exc())
            sys.exit(1)

Error:

Code errors: Exception has occurred: TypeError
an integer is required  File "C:\Users\user\Documents\GitLab\various-scripts\OTRS Auto-Reporting\Analysts-Locked\otrs_reporting_analysts_locked.py", line 160, in <module>
    for ticket_type in ticket_types:
                       ^^^^^^^^^^^^
TypeError: an integer is required

However I was able to fix the issue by either:

  • uncomment the print statement at the end of the try block
  • removing the try/except block
  • running the script directly without debugger

And now I am completely confused. Why is the print statement doing anything? Why does it error with the debugger but works fine without? What has all this to do with an expected integer?

Can anyone make sense of this?

I am using Python 3.12.7 64 bit ( Microsoft Store) and the respective VS-Code plugin.

13
  • "uncomment the print statement at the end of the try block": that print function has a problem (concatenating a string with a list won't work), but that's not what this error shows. That's simply another error in the code. Commented Nov 18, 2024 at 11:17
  • If things work because you remove things below the offending line, and this is in a loop, it may be that you assign some value to ticket_types inside the loop. Commented Nov 18, 2024 at 11:18
  • 1
    Which debugger are you using? I don't know VS Code that well, let alone any plugins; does the plugin state what debugger it uses? Can you try another debugger? Commented Nov 18, 2024 at 11:19
  • 1
    "except Exception as e:": traditaional warning that this is considered bad code, catching all errors. Commented Nov 18, 2024 at 11:20
  • 1
    The actual error message doesn't make any sense to me, tbh. It feels like something else is going on; or this is a (very) bad debugger. Commented Nov 18, 2024 at 11:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.