Trying to announce to a UDP tracker (Bittorrent)

Need some help implementing the UDP tracker annoucne part of the torrent protocol.

I'm trying to implement UDP announcing, and I got the code for connecting to said tracker working, I think (it sends back a proper reply.) However, whenever I try to send an announce to said trackers, I either get no response back or a malformed packet error ([0, 0, 0, 3, 144, 252, 21, 229, 109, 97, 108, 102, 111, 114, 109, 101, 100, 32, 112, 97, 99, 107, 101, 116]). I don't really understand what I'm doing wrong, and I'd really appreciate some help.

I'm trying to follow the bep_0015 as closely as possible.

The relevant function is called announce_udp in the file linked above.