Python2中没有这个问题

python3中

hashlib.md5(data)函数中data 参数的类型应该是bytes

hash前必须把数据转换成bytes类型

Python 2.7.12 (default, Dec  4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from hashlib import md5
>>> name = md5("hello")
>>> print(name.hexdigest())
5d41402abc4b2a76b9719d911017c592
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from hashlib import md5
>>> name = md5("hello")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Unicode-objects must be encoded before hashing
>>> name = md5("hello".encode("utf-8"))
>>> print(name.hexdigest())
5d41402abc4b2a76b9719d911017c592

Python hashlib Unicode-objects must be encoded before hashing的更多相关文章

  1. Python——在Unicode和普通字符串之间转换

    1.1. 问题 Problem You need to deal with data that doesn't fit in the ASCII character set. 你需要处理不适合用ASC ...

  2. Python: 在Unicode和普通字符串之间转换

    Unicode字符串可以用多种方式编码为普通字符串, 依照你所选择的编码(encoding): <!-- Inject Script Filtered --> Toggle line nu ...

  3. python hashlib模块 md5加密 sha256加密 sha1加密 sha512加密 sha384加密 MD5加盐

      python hashlib模块   hashlib hashlib主要提供字符加密功能,将md5和sha模块整合到了一起,支持md5,sha1, sha224, sha256, sha384, ...

  4. 关于python hashlib模块的使用

    hashlib hashlib主要提供字符加密功能,将md5和sha模块整合到了一起,支持md5,sha1, sha224, sha256, sha384, sha512等算法 #!/usr/bin/ ...

  5. python decode unicode encode

    字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(en ...

  6. Python中Unicode字符串

    Python中Unicode字符串 字符串还有一个编码问题. 因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特(bit)作为一个字节(byte ...

  7. hashlib使用时出现: Unicode-objects must be encoded before hashing

    # hashlib.md5(data)函数中,data参数的类型应该是bytes# hash前必须把数据转换成bytes类型>>> from hashlib import md5 F ...

  8. python中unicode和str的组合

    python中unicode对象和str对象拼接在一起,会自动将str对象转换成unicode对象 即:a="aa" b=u"bb" c=a+b type(c) ...

  9. django注册在使用hashlib对密码加密时报Unicode-objects must be encoded before hashing

    在使用sh1等hashlib方法进行加密时报:Unicode-objects must be encoded before hashing 解决办法:对要加密的字符串指定编码格式 解决之前: s1=s ...

随机推荐

  1. 安卓使用讯飞sdk报错

    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.iflytek.cloud.SpeechSy ...

  2. vijos题解

    Vijos题解 题库地址:https://vijos.org/p P1001 谁拿了最多奖学金 题意:按照指定要求计算奖学金,直接用if判断即可 #include<iostream> us ...

  3. ECSHOP产品内容页新增上传功能

    第一步:在 admin\templates\goods_info.htm中 <span class="tab-back" id="article-tab" ...

  4. K8s一键安装

    安装案例: 系统:Centos可以多台Master(Master不能低于3台)多台Node此案例使用三台Master两台Node,用户名root,密码均为123456 master 192.168.2 ...

  5. python+宝塔nginx+uwsgi的搭建方法

    第一: 百度搜索宝塔,然后进入root,安装lnmp,根据情况选择选择需的选项进行安装,nginx必须安装. 第二: 进入宝塔,新建网站,网站的目录,先随便指定,绑定好的域名, 进入root,到宝塔网 ...

  6. AT3611-Tree MST【点分治,最小生成树】

    正题 题目链接:https://www.luogu.com.cn/problem/AT3611 题目大意 给出\(n\)个点的一棵树. 现在有一张完全图,两个点之间的边权为\(w_x+w_y+dis( ...

  7. Python3入门系列之-----内置的文件操作模块OS

    前言 在自动化测试中,经常需要查找操作文件,比如说查找配置文件(从而读取配置文件的信息),查找测试报告(从而发送测试报告邮件),经常要对大量文件和大量路径进行操作,这个时候就需要用到os模块. 使用前 ...

  8. 解决报错:Unable to process Jar entry [org/springframework/jmx/export/annotation/*****]

    情况说明:从gitub上clone的maven项目,pox.xml配置中的依赖,自己的repository都有,所以正常update project ,正常clean,install,整个过程无报错 ...

  9. VMware vSphere 7 Update 3 下载

    请访问原文链接:https://sysin.org/blog/vmware-vsphere-7-u3/,查看最新版.原创作品,转载请保留出处. vSphere 7 Update 3 已经宣布可用,即将 ...

  10. 实现一个简单的侧边导航Winform程序框架

    目录 简介 实现导航面板 实现方法 使用方法 实现标题栏 窗体拖拽及最大化 自定义窗体按钮 标题显示 按钮设置 实现状态栏 整体使用 参考文章 简介 每次新项目都要想着界面怎么设计好,但想来想去上位机 ...