最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Weird Python Error "TypeError: an integer is required" on a List - Only in Debugger - Fixed by adding print -

programmeradmin8浏览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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论