title: Python struct.pack: required argument is not an integer. Input are all integers
body: <p>I use a modified version of <a href="https://github.com/houluy/UDP" rel="nofollow noreferrer">https://github.com/houluy/UDP</a> to parse and send raw UDP packets. However, sometimes it randomly triggers an exception on  struct.pack(). It does not seem to be related to a certain packet, but when I increase the packet rate the error seems to be thrown.</p>
  
  <p>Relevant code:</p>
  
  <pre><code>src_port = src_addr[1]
  dest_port = dest_addr[1]
  
  udp_length = 8 + len(data)
  
  checksum = 0
  pseudo_header = struct.pack('!BBH', zero, protocol, udp_length)
  pseudo_header = src_ip + dest_ip + pseudo_header
  try:
      udp_header = struct.pack('!4H', src_port, dest_port, udp_length, checksum)
  except struct.error as err:
      print(err)
      print("Port: " + str(src_port) + " = " + str(type(src_port)))
      print("DestPort: " + str(dest_port) + " = " + str(type(src_port)))
      print("Len: " + str(udp_length) + " = " + str(type(src_port)))
      print("Checksum: " + str(checksum) + " = " + str(type(src_port)))
  </code></pre>
  
  <p>struct.pack throws the error required argument is not an integer. As such I print the types in the except clause to verify what is going wrong. I get the following output:</p>
  
  <pre><code>required argument is not an integer
  Port: 123 = &lt;class 'int'&gt;
  DestPort: 123 = &lt;class 'int'&gt;
  Len: 16 = &lt;class 'int'&gt;
  Checksum: 0 = &lt;class 'int'&gt;
  </code></pre>
  
  <p>I don't have the slightest clue what is going wrong here. If I were to explicitly cast the value to integers to be sure with the following line, the exact same thing happens</p>
  
  <pre><code>udp_header = struct.pack('!4H', int(src_port), int(dest_port), int(udp_length), int(checksum))
  </code></pre>
  
  <p>Perhaps I am missing something, but I don't have any clue what is going wrong here. Running Python 3.6.7 on CentOS Linux release 7.5.1804.</p>