Why is my UDP data enclosed in (b"")?

Whenever I retrieve data via UDP it’s being retrieved like this:

b"{‘EHZ’, 1582134363.658, 20145, 23499, 20204, 21549, 22799, 20228, 14193, 6997, 13085, 11014, 6070, 12098, 17681, 16889, 18778, 23669, 17933, 17199, 19970, 17204, 16579, 13997, 14233, 15419, 13732}"

Why is it enclosed with (b"")?

Correct me if I’m wrong.

Just found out it’s a python thing. For anyone who’s using later version, simply use .decode() function to remove this because b"" indicates that the data are bytes array.

1 Like

Great. @iannesbitt please consider adding this helpful tidbit to the manual.

That’s correct, it’s received as something Python calls a bytes object, which is closely related to a string but is encoded as bytes instead of, for example, UTF-8. To decode from bytes to UTF-8 and back is very easy:

>>> bytes = b'this is a bytes object'
>>> str = bytes.decode()
>>> str    # this actually isn't a bytes object, but a regular UTF-8 string
'this is a bytes object'
>>> str.encode()
b'this is a bytes object'