0

I have the following byte string inside a database field:

"G\xb0A\x12C\xa4\xf3@\x03/|\xda\x86\x15\x92\x11\x08\xe4?\xd23\xd5<\x90\xf1\xab\x1a\xe5\xae\x15;\xef\x98\x93\xf8\x14\x85\x08Fw\x18fn\x97\xca\x84\xc6\xaf\'\xedm\xf2B\x8c\x10\xd7+\xbeM\x9e\xe7\xc6;\x98P\xc6\t\xb3\xef\x0b\x87\xa6\x0fd\xf9J\xea=\x03a\xb5\x19\xff{X\x14\x82)\xbd\x0b\xfd\xbbIX\xb8\x01\xbb\"\xde,4\xc94\xe3R\x81\xa5[\xa2\xd7\xead\r\x88\r2\x83\xf2Bu\xcf\x10\x16n$~,K\x92\xbc\x8a\xf8\xe9\x99}\xf15.\xde\xe3\xe0\xa9\x9a.\x00\"\x00\x9e\xb3V\xc6Z\x8e\x14\x19:5\xc6z\xfe\x95\x88=\x15\xc4i3\x87\x8c(3m\x8c\n\xc3N \xbc\t\xb7\x98RA\"\x85\'\x88\xca\x17O\xe6\xb7\xd8\xc8i\xd0\x8e\n\x10\xd2T\xd6\xacd)^]\xd9\xa2\"\xe3\xba;y\xb6=\xaca\x08\xc6\xff\xe5\xf78\x88\xad.\xc9*\x00\xdb\xc9(#\x93\x08\xd5\xa1\xbd\xac\x86\xf0i\xe5z\xc5\x0f\xb9V\x8eR6\x8a\xb0-\xe1"

In my Django app when I print it from the database, the console displays literally everthings that's above. However if I print the same string from a variable like so:

data = "G\xb0A\x12C\xa4\xf3@\x03/|\xda\x86\x15\x92\x11\x08\xe4?"...........

The console tries to interpret it as a byte and displays it like so:

2â≥Bu╧►▬n$~,KÆ╝è°ΘÖ}±5................

This is what I want to achieve. How can I get the byte string from the database to be interpreted as binary data instead as a string?

agf
  • 171,228
  • 44
  • 289
  • 238

2 Answers2

2

I'm guessing this is the difference between str() and repr().

Community
  • 1
  • 1
Ross Patterson
  • 5,702
  • 20
  • 38
0

If the data has structure you can use struct

Or you can use xdrlib

Aaron G
  • 21
  • 2