title: Extracting TCP data with Scapy
body: <p>I'm currently trying to extract the payload of a TCP packet (which is just a single letter) with Scapy, but it keeps giving me a NoneType exception after going through the first two packets.</p>
  <pre><code>from scapy.all import *
  import base64
  
  capture = rdpcap('Data.pcapng') # pcap file
  
  output = open('output.bin','wb') # save dumped data to output.bin
  
  for packet in capture:
      # if packet is ICMP and type is 8 (echo request)
      if packet[TCP].src == '172.16.139.128': 
          output.write(packet[TCP].payload) # write packet data to output.bin
  </code></pre>
  <p>The exception:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/packet.py&quot;, line 372, in __getattr__
      fld, v = self.getfield_and_val(attr)
  TypeError: cannot unpack non-iterable NoneType object
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File &quot;exploit.py&quot;, line 10, in &lt;module&gt;
      if packet[TCP].src == '172.16.139.128': 
    File &quot;/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/packet.py&quot;, line 374, in __getattr__
      return self.payload.__getattr__(attr)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/packet.py&quot;, line 372, in __getattr__
      fld, v = self.getfield_and_val(attr)
    File &quot;/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scapy/packet.py&quot;, line 1600, in getfield_and_val
      raise AttributeError(attr)
  AttributeError: src
  </code></pre>
  <p>Does anyone know what's causing this? It should be outputting more.</p>