>> any attempt to call tcp.payload() will result in a TypeError message (cannot call str).
type error tells you everything you need to know -- tcp.payload is apparently str (and so you cannot call it) On Thu, Feb 13, 2014 at 4:37 PM, Emanuele Di Pascale <dipas...@tcd.ie>wrote: > Hello, > I'm trying to write a POX module to identify http GET requests to specific > IP addresses and react based on the page requested, but I'm struggling with > the http part. There doesn't seem to be a POX http packet class, so I > assume I need to convert the raw bytes read from the wire into a string > representation of the http message. However the couple of approaches I > tried all failed miserably. Specifically, after retrieving the tcp packet > in my PacketIn handler like this: > > tcp = event.parsed.find('tcp') > if tcp is not None and tcp.parsed: > > any attempt to call tcp.payload() will result in a TypeError message > (cannot call str). Calling tcp.next.decode("utf-8") and trying to print > that through log.debug will throw a "TypeError: not all arguments converted > during string formatting" exception . And similarly I get an exception for > > dlen = len(tcp.next) > (http) = struct.unpack('!'+str(dlen)+'s', tcp.next) > log.debug("Http payload: " + http) > > I'm assuming the problem might be the CR+LF characters in the http > message, but I have no way of knowing the length of the message as it > depends on the page that's being requested. It could also be something > else, as I'm new to Python and possibly missing something very obvious. Any > hints? > > Thanks in advance! > > Emanuele Di Pascale >