Omnimaga

General Discussion => Technology and Development => Computer Programming => Topic started by: Snake X on December 07, 2012, 10:52:49 am

Title: removing b from bytes object
Post by: Snake X on December 07, 2012, 10:52:49 am
Another day another runtime error... At least for me anyways :P

Anyways, when I have a string encoded (for example: "test".encode()), it comes out to be: b'test'

The thing is, is that this bytes object is being sent in a packet, which somehow gets that prefix b parsed into the text itself.

So, this means that in the packet data, it is being sent as "btest" (I examined it in wireshark tcp stream) when I REALLY need it to just be sent as "test" without this b before it.

I cannot simply use .lstrip("b"), for its not a string object, nor can I simply .decode() and then use .encode() again as that would just put it back to "btest" in the packet data.

I somehow need to perform some function to manipulate the bytes object to remove this "b" so that it can be read correctly by the server im sending it to.


I'm at an extreme loss here....  ???



EDIT: Is it possible there's something else that placed this "b" into the byte object instead of .encode() itself?


EDIT 2: I fixed it :D after THOROUGHLY tracing it lol
Title: Re: removing b from bytes object
Post by: stevon8ter on December 07, 2012, 01:20:19 pm
Could you share your solution for the other python programmers...? you never know someone could use the solution...
(I'm not a python programmer myself tho)
Title: Re: removing b from bytes object
Post by: Snake X on December 07, 2012, 01:26:20 pm
Oh it had nothing to do with python itself, it was with my own code that messed it up, lol

Basically I added something that was putting that extra b in there in a library
Title: Re: removing b from bytes object
Post by: stevon8ter on December 07, 2012, 04:03:35 pm
Oooh ok lol :p

But it's still the best to tell people it was your own code that was a bit wrong, so people know that's it not coming from the encode decode
Title: Re: removing b from bytes object
Post by: Snake X on December 07, 2012, 11:57:34 pm
Ah, yeah. Indeed the b before the string is not part of the characters in bytes. Btw it wasn't MY code, it was an error in a small lib someone wrote
Title: Re: removing b from bytes object
Post by: stevon8ter on December 08, 2012, 08:54:32 am
Yeah ok sorry :p then just say it was the librarian xDDDDDDDDDDDDDD