2

I'm attempting to store IP packet payloads in a PostgreSQL database with Django.

Currently, I'm storying the payload as a CharField.

I'm getting this error:

django.db.utils.DatabaseError: invalid byte sequence for encoding "UTF8": 0xedbc93
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".

Is there any way to sanely store this data? I'm able to do str(packet.payload) with no errors, but when Django tries to save the object it throws the encoding error. A bytestring seems like the obvious solution, but it doesn't look like Django supports that.

asked Feb 12, 2012 at 22:01
0

1 Answer 1

4

If you want to store arbitrary bytestrings, you should declare them as such. Many (most?) sequences of bytes are not valid UTF-8, so it isn't a good way to store them. A CharField is for storing text, and you don't have text.

The answers to this question will likely be helpful: Django Blob Model Field

answered Feb 12, 2012 at 22:31
Sign up to request clarification or add additional context in comments.

1 Comment

What he said. An IP packet payload is a binary blob. It's neither a string nor is it Unicode. Even if the protocol is 100% Unicode text, it is possible for a packet payload to be invalid Unicode.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.