What instantly meets the eye is that there might be a typo in the IP address specifier:
if UDP in packet:
print(f"UDP Packet: {packet[UDP].src}:{packet[UDP].sport} -> {packet[IP].dst}:{packet[UDP].dport}")
Instead of {packet[UDP].src}
one probably wants to write {packet[IP].src}
.