title: TypeError: Argument 'payload' has incorrect type (expected bytes, got str). How can I fix it? Why it works on Python 2 but not using Python 3?
body: <p>I am pretty new in Python and I have the following problem using *scapy** library. Here you can find the entire code (but I think that it is not so important because the error is on a specific line: <a href="https://github.com/AndreaNobili/replace_download/blob/master/replace_download.py" rel="nofollow noreferrer">https://github.com/AndreaNobili/replace_download/blob/master/replace_download.py</a>)</p>
  
  <p>Into a <strong>Python 2</strong> project I have the following two lines:</p>
  
  <pre><code>modified_packet = set_load(scapy_packet, "HTTP/1.1 301 Moved Permanently\nLocation: https://www.rarlab.com/rar/wrar590.exe\n\n")
  
  # Replace the original packet payload with the packet forget by scapy:
  packet.set_payload(str(modified_packet))
  </code></pre>
  
  <p>This is the code of my <strong>set_load()</strong> function:</p>
  
  <pre><code>def set_load(packet, load):
      #pdb.set_trace()
      print("set_load() START")
  
      # When the victim try to download a ".exe" file he\she is redirected to this other ".exe" link:
      packet[scapy.Raw].load = load
      # The value of the following fields are changed because the file is changed, they will be removed and
      # scapy automatically recalculate the values of these fields inserting the correct values:
      del packet[scapy.IP].len
      del packet[scapy.IP].chksum
      del packet[scapy.TCP].chksum
      return packet
  </code></pre>
  
  <p>So basically I am forging a packet using <strong>scapy</strong>, finally I am setting the payload of the original <strong>packet</strong> variable with the payload forged by <strong>Scapy</strong>:</p>
  
  <pre><code>packet.set_payload(str(modified_packet))
  </code></pre>
  
  <p><strong>NOTE:</strong> The <strong>packet variable is not a **scapy</strong> packet but a packet obtained using <strong>netfilterqueue</strong></p>
  
  <p>Running my script with <strong>Python 2</strong> it works fine but using <strong>Python 3</strong> this last line give me the following error:</p>
  
  <pre><code>TypeError: Argument 'payload' has incorrect type (expected bytes, got str)
  &gt; /root/Documents/PycharmWS/replace_download/replace_download.py(61)process_packet()
  -&gt; packet.set_payload(str(modified_packet))  
  </code></pre>
  
  <p>So I am converting the <strong>scapy</strong> packet into a <strong>string</strong> and then I am setting the payload of the original <strong>netfilterqueue</strong> packet but it seems that it is expecting a <strong>bytes</strong></p>
  
  <p>How can I fix this problem? What am I missing?</p>
  
  <p>Another doubt is: why Python 2 it is working fine? I suspect that the <strong>netfilterqueue</strong> dependency version used by Python 2 is slightly different from the one used by Python 3 and in the old version expected a <strong>string</strong> instead a <strong>bytes</strong> parameter. Is this reasoning correct or am I missing something?</p>