Open bsmelo opened 7 years ago
Ok the issue here is that in python2 strings were byte-strings, so one character equals one byte. in python3, strings are utf-8 strings. That means, if you want your strings to mean bytes, you have to do conversion manually. This is what you are missing in this instance. For the first example you give, you have to make sure coap's i2m
method on the _CoAPOptsField
returns byte strings. to do that, you change line 174 to
return b""
and line 189 to
return (opts).encode("ascii")
string literals starting with b" are bytestrings, and encoding as ascii makes the result also bytestrings. I don't know if that fixes your second issue too, you would have to provide me with the pcap file so I can be sure. However, I do suspect you have to make sure that the getfield
method on line 159 returns bytestrings, so maybe replacing "" with b"" on that line does the trick.
@bsmelo You cannot just copy module from scapy2 to scapy3k. It has to be ported. @Inachos already described one of the differences related to str vs. bytes. But there are more differences between python2 and python3.
Hello,
I'm new to scapy (scapy3k as well), but I want to use it to manipulate some CoAP packets.
I've found a CoAP layer implementation on the contrib folder of the original scapy, consisting of two files (one of them is just a unittest, as far as I understand): contrib/coap.uts contrib/coap.py
I've added these two files (just copied) to scrapy3k's contrib folder, but I'm having some problems using this layer (I want to use it with scapy3k because I will also need another library in my program, which is only available for Python >= 3.5).
Could someone please give me some pointers on how to solve this issue? I don't know if it's simple enough, or if I could at least get some tips on where to focus when looking/changing things on coap.py... I'd really appreciate it!