相关疑难解决方法(0)

无法获取字符串的 sha256 哈希值

我正在尝试获取字符串的哈希值:

hs = hashlib.sha256(get_some_string()).hexdigest()
Run Code Online (Sandbox Code Playgroud)

...但我收到一个错误:

类型错误:在散列之前必须对 Unicode 对象进行编码

python hash python-3.x

9
推荐指数
1
解决办法
2万
查看次数

Python,UnicodeDecodeError

我收到此错误:

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)

python unicode

7
推荐指数
2
解决办法
3万
查看次数

标签 统计

python ×2

hash ×1

python-3.x ×1

unicode ×1