Python 3的代码:Python 2 vs 3.相同的输入,不同的结果。 MD5哈希
def md5hex(data):
""" return hex string of md5 of the given string """
h = MD5.new()
h.update(data.encode('utf-8'))
return b2a_hex(h.digest()).decode('utf-8')
的Python 2代码:
def md5hex(data):
""" return hex string of md5 of the given string """
h = MD5.new()
h.update(data)
return b2a_hex(h.digest())
输入蟒3:
>>> md5hex('bf5¤7¤8¤3')
'61d91bafe643c282bd7d7af7083c14d6'
输入蟒2:
>>> md5hex('bf5¤7¤8¤3')
'46440745dd89d0211de4a72c7cea3720'
请告诉我要去Ø N +
编辑:
def genurlkey(songid, md5origin, mediaver=4, fmt=1):
""" Calculate the deezer download url given the songid, origin and media+format """
data = b'\xa4'.join(_.encode("utf-8") for _ in [md5origin, str(fmt), str(songid), str(mediaver)])
data = b'\xa4'.join([md5hex(data), data])+b'\xa4'
if len(data)%16:
data += b'\x00' * (16-len(data)%16)
return hexaescrypt(data, "jo6aey6haid2Teih").decode('utf-8')
这一切问题的开始这个B '\ XA4' 在Python 2的代码在另一个函数。该字节不出现在Python 3
有了这样的一个我得到正确的MD5哈希工作......在python3
您是否尝试过使用'u'前缀字符串? –
@NilsWerner,是的。同样的结果。 –
你用'from __future__ import unicode_literals'试过了吗? – Gribouillis