DjangoUnicodeDecodeError when saving pickle'd data

I have a simple object dictthat I am trying to save to the database after it has been launched through pickle. It seems that Django does not like to try to code this error. I checked with MySQL and the query does not even get before it throws an error, so I do not think this is a problem. Saving is dictas follows:

{
    'ordered': [
        {   'value': u'First\xd1ame Last\xd1ame',
            'label': u'Full Name' },
        {   'value': u'123-456-7890',
            'label': u'Phone Number' },
        {   'value': u'user@nowhere.org',
            'label': u'Email Address' } ],
    'cleaned_data': {
        u'Phone Number': u'123-456-7890',
        u'Full Name': u'First\xd1ame Last\xd1ame',
        u'Email Address': u'user@nowhere.org' },
    'post_data': <QueryDict: {
        u'Phone Number': [u'1234567890'],
        u'Full Name_1': [u'Last\xd1ame'],
        u'Full Name_0': [u'First\xd1ame'],
        u'Email Address': [u'user@nowhere.org'] }>,
    'user': <User: itis>
}

Outstanding error:

'utf8' codec cannot decode bytes at position 52-53: invalid data.

Position 52-53 is the first instance \xd1(ร‘) in the pickled data.

StackOverflow , . , MySQL. . Google Unicode .

, , ร‘, .

+3
3

@prometheus, . base64 pickle.dumps() . base64 , pickle.loads().

:

## Put the information into the database:
self.raw_data = base64.b64encode(pickle.dumps(data))

## Get the information out of the database:
return pickle.loads(base64.b64decode(self.raw_data))

@prometheus.

+3

, Python bug-tracker:

python . ASCII . Python , 0 ASCII.

pickle + base64 , .

, , , 0 ASCII - , Python. , , Django unicode() , -ASCII.

+2

. , .

The worse problem is that etching is unsafe - if the database can get its data from anywhere, it can get malicious etching data.

+1
source

Source: https://habr.com/ru/post/1738692/


All Articles