Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python DatabaseError:除非使用可以解释8位ByTestRing的文本工厂(如text\u factory=str),否则不能使用8位ByTestRing_Python_Sql_Django - Fatal编程技术网

Python DatabaseError:除非使用可以解释8位ByTestRing的文本工厂(如text\u factory=str),否则不能使用8位ByTestRing

Python DatabaseError:除非使用可以解释8位ByTestRing的文本工厂(如text\u factory=str),否则不能使用8位ByTestRing,python,sql,django,Python,Sql,Django,我试图在Django中加密一个值,但我总是得到一个数据库错误。我猜它不想在数据库中存储8位字符串。有办法绕过它吗?我在本地机器上使用SQlite,在生产中使用postgreSQL。还有,这是我的代码 def set_message(self, raw_message): last_four = raw_message[len(raw_message)-4:len(raw_message)] rest = '*' for n in range(0,len(raw_messa

我试图在Django中加密一个值,但我总是得到一个数据库错误。我猜它不想在数据库中存储8位字符串。有办法绕过它吗?我在本地机器上使用SQlite,在生产中使用postgreSQL。还有,这是我的代码

def set_message(self, raw_message):
    last_four = raw_message[len(raw_message)-4:len(raw_message)]
    rest = '*'
    for n in range(0,len(raw_message)-5):
        rest=rest+'*'
    self.message_string = rest+str(last_four)

    extra_words = len(raw_message) % 8 #since Strings for DES must be a multiple of 8 in length

    add_words_length = 8 - extra_words

    for x in range(0,add_words_length):
        raw_message = raw_message + 'X'

    obj=DES.new('abcdefgh', DES.MODE_ECB)

    encrypt_raw_message=obj.encrypt(raw_message)

    self.message = encrypt_raw_message

    self.save()