我正在尝试获取字符串的哈希值:
hs = hashlib.sha256(get_some_string()).hexdigest()
Run Code Online (Sandbox Code Playgroud)
...但我收到一个错误:
类型错误:在散列之前必须对 Unicode 对象进行编码
我收到此错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 4: ordinal not in range(128)
Run Code Online (Sandbox Code Playgroud)
我尝试设置许多不同的编解码器(在标题中# -*- coding: utf8 -*-),甚至使用u"string",但它仍然出现.
我该如何解决?
编辑:我不知道导致这个的实际字符,但由于这是一个递归浏览文件夹的程序,它必须在其名称中找到一个包含奇怪字符的文件
码:
# -*- coding: utf8 -*-
# by TerabyteST
###########################
# Explores given path recursively
# and finds file which size is bigger than the set treshold
import sys
import os
class Explore():
def __init__(self):
self._filelist = []
def exploreRec(self, folder, treshold):
print folder
generator = os.walk(folder + "/")
try:
content = generator.next()
except:
return
folders …Run Code Online (Sandbox Code Playgroud)