English 中文(简体)
DjangoUnicodeDecodeError, whilestoringferle d data
原标题:DjangoUnicodeDecodeError while storing pickle d data

页: 1 试图通过<代码>pickle在数据库中储存的物体Im。 Django似乎无意试图将这一错误编码。 我与我的SQL进行了检查,在错失之前,问询甚至没有到那里,因此我不认为是问题。 http://www.un.org/Depts/DGACM/index_french.htm stor:

{
     ordered : [
        {    value : u Firstxd1ame Lastxd1ame ,
             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 Firstxd1ame Lastxd1ame ,
        u Email Address : u user@nowhere.org  },
     post_data : <QueryDict: {
        u Phone Number : [u 1234567890 ],
        u Full Name_1 : [u Lastxd1ame ],
        u Full Name_0 : [u Firstxd1ame ],
        u Email Address : [u user@nowhere.org ] }>,
     user : <User: itis>
}

引出的错误是:

utf8 代码c 可在第52-53号立场中打上密码:无效数据。

第52-53号立场是选取数据中的<编码>xd1(Ñ)的首例。

迄今为止,我在StackOverflow周围挖掘了几个问题,数据库对物体的编码是错误的。 这不利于我,因为现在还没有我的SQL问题。 这是在数据库之前进行的。 谷歌在寻找选取数据上的单编码错误时也无帮助。

也许值得提及的是,如果我不使用Ñ,那么该法典就会被罚款。

最佳回答

由于“prometheus”,我找到了解决办法。 基本上,在将数据库输入数据库之前,你可以使用第64号基数来编码<编码>>。 之后,您将转而使用第64号基数,在将数据库输入到<编码>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。

问题回答

我认为没有必要这样做。 通常应有可能将任何双向数据储存在数据库中。

更糟糕的是,如果数据库能够从任何地方获取数据,则收集数据是不安全的。





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签