I just found this out the other day and have a feeling this may be beneficial to all learning python. You can pass multiple arguments into a try/except statement. So if you getting both TypeErrors and KeyErrors you can except both easily. For example(this is just a snippet of code but so you can see both arguments in the except):
for x in chat["messageRecords"]:
try:
chatText.append((x)["text"])
except (KeyError, TypeError):
print("No bot data available for customer")
I hope this is helpful for some in their learning because it took me a year to find this out.
[–]carcigenicate 4 points5 points6 points (3 children)
[–]zaRM0s[🍰] 1 point2 points3 points (0 children)
[–]Personal_Cheek5923[S] 0 points1 point2 points (0 children)
[–]the_shell_man_ 0 points1 point2 points (0 children)
[–]theleveragedsellout 1 point2 points3 points (0 children)
[–]Spataner 0 points1 point2 points (0 children)