admin管理员组文章数量:1026134
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.
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.
本文标签:
版权声明:本文标题:Weird Python Error "TypeError: an integer is required" on a List - Only in Debugger - Fixed by adding print - 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745624475a2159776.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论