Search code examples
unicodewxpythonpython-2.6scapy

Scapy - Raw layer to string and into a wx.TextCtrl


I'm using scapy to show all layers of a packet and when the packet has a UDP layer and Raw it sometimes gives me an 'UnicodeDecodeError: 'charmap' codec can't decode byte...' and I dont know what to do .. help? this is the line of code that makes trouble :

 self.txt.SetValue(str(pkt.getlayer(Raw).load))

I need a way to show the Raw data in the TextCtrl.


Solution

  • Try passing the data as unicode instead of a string:

    self.txt.SetValue(u'%s' % (pkt.getlayer(Raw).load))
    

    I wouldn't be too surprised if this didn't work though, so be sure to read up on how to use unicode in Python:

    You should also check out the following articles:

    If all else fails, you can always try converting the unicode to ascii using this fun package: