Author Topic: removing b from bytes object  (Read 3540 times)

0 Members and 1 Guest are viewing this topic.

Offline Snake X

  • Ancient Veteran
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 810
  • Rating: +33/-8
    • View Profile
removing b from bytes object
« 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
« Last Edit: December 07, 2012, 12:45:22 pm by Snake X »
Loved this place, still the best producers of power metal, and sparked my dreams of coding.

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: removing b from bytes object
« Reply #1 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)
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline Snake X

  • Ancient Veteran
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 810
  • Rating: +33/-8
    • View Profile
Re: removing b from bytes object
« Reply #2 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
Loved this place, still the best producers of power metal, and sparked my dreams of coding.

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: removing b from bytes object
« Reply #3 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
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER

Offline Snake X

  • Ancient Veteran
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 810
  • Rating: +33/-8
    • View Profile
Re: removing b from bytes object
« Reply #4 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
« Last Edit: December 07, 2012, 11:57:47 pm by Snake X »
Loved this place, still the best producers of power metal, and sparked my dreams of coding.

Offline stevon8ter

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 663
  • Rating: +10/-0
    • View Profile
Re: removing b from bytes object
« Reply #5 on: December 08, 2012, 08:54:32 am »
Yeah ok sorry :p then just say it was the librarian xDDDDDDDDDDDDDD
None of my posts are meant offending... I you feel hurt by one of my posts, tell me ... So i can appoligise me and/or explain why i posted it


Hi there, I'm the allmighty (read as: stupid, weak...) STEVON8TER