hashlib

Remove all characters from a string who's ordinals are out of range

亡梦爱人 提交于 2019-12-01 06:20:25
问题 What is a good way to remove all characters that are out of the range: ordinal(128) from a string in python? I'm using hashlib.sha256 in python 2.7. I'm getting the exception: UnicodeEncodeError: 'ascii' codec can't encode character u'\u200e' in position 13: ordinal not in range(128) I assume this means that some funky character found its way into the string that I am trying to hash. Thanks! 回答1: new_safe_str = some_string.encode('ascii','ignore') I think would work or you could do a list

unsupported hash type when installing plone

血红的双手。 提交于 2019-12-01 06:15:02
问题 I tried to install plone but I have a problem when I run the script install.sh. Here are the errors details: raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha256 ERROR:root:code for hash sha384 was not found ValueError: unsupported hash type sha512 I read in a forum that this error may be caused by a version of Plone which is not compatible with the python version that is on the OS. But, here is what is said on the official website of plone: The Plone

Compare result from hexdigest() to a string

那年仲夏 提交于 2019-11-30 20:31:43
I've got a generated MD5-hash, which I would like to compare to another MD5-hash from a string. The statement below is false, even though they look the same when you print them and should be true. hashlib.md5("foo").hexdigest() == "acbd18db4cc2f85cedef654fccc4a4d8" Google told me that I should encode the result from hexdigest() , since it doesn't return a string. However, the code below doesn't seem to work either. hashlib.md5("foo").hexdigest().encode("utf-8") == "foo".encode("utf-8") Python 2.7, .hexdigest() does return a str >>> hashlib.md5("foo").hexdigest() ==

Determine whether any files have been added, removed, or modified in a directory

痴心易碎 提交于 2019-11-30 04:01:17
问题 I'm trying to write a Python script that will get the md5sum of all files in a directory (in Linux). Which I believe I have done in the code below. I want to be able to run this to make sure no files within the directory have changed, and no files have been added for deleted. The problem is if I make a change to a file in the directory but then change it back. I get a different result from running the function below. (Even though I changed the modified file back. Can anyone explain this. And

Max limit of bytes in method update of Hashlib Python module

时光怂恿深爱的人放手 提交于 2019-11-29 15:15:48
I am trying to compute md5 hash of a file with the function hashlib.md5() from hashlib module. So that I writed this piece of code: Buffer = 128 f = open("c:\\file.tct", "rb") m = hashlib.md5() while True: p = f.read(Buffer) if len(p) != 0: m.update(p) else: break print m.hexdigest() f.close() I noted the function update is faster if I increase Buffer variable value with 64, 128, 256 and so on. There is a upper limit I cannot exceed? I suppose it might only a RAM memory problem but I don't know. Big (≈ 2**40 ) chunk sizes lead to MemoryError i.e., there is no limit other than available RAM. On

Finding duplicate files via hashlib?

喜欢而已 提交于 2019-11-29 12:25:38
I know that this question has been asked before, and I've saw some of the answers, but this question is more about my code and the best way of accomplishing this task. I want to scan a directory and see if there are any duplicates (by checking MD5 hashes) in that directory. The following is my code: import sys import os import hashlib fileSliceLimitation = 5000000 #bytes # if the file is big, slice trick to avoid to load the whole file into RAM def getFileHashMD5(filename): retval = 0; filesize = os.path.getsize(filename) if filesize > fileSliceLimitation: with open(filename, 'rb') as fh: m =

Using hashlib to compute md5 digest of a file in Python 3

ぐ巨炮叔叔 提交于 2019-11-28 11:54:45
With python 2.7 the following code computes the mD5 hexdigest of the content of a file. (EDIT: well, not really as answers have shown, I just thought so). import hashlib def md5sum(filename): f = open(filename, mode='rb') d = hashlib.md5() for buf in f.read(128): d.update(buf) return d.hexdigest() Now if I run that code using python3 it raise a TypeError Exception: d.update(buf) TypeError: object supporting the buffer API required I figured out that I could make that code run with both python2 and python3 changing it to: def md5sum(filename): f = open(filename, mode='r') d = hashlib.md5() for

Finding duplicate files via hashlib?

旧时模样 提交于 2019-11-28 06:09:43
问题 I know that this question has been asked before, and I've saw some of the answers, but this question is more about my code and the best way of accomplishing this task. I want to scan a directory and see if there are any duplicates (by checking MD5 hashes) in that directory. The following is my code: import sys import os import hashlib fileSliceLimitation = 5000000 #bytes # if the file is big, slice trick to avoid to load the whole file into RAM def getFileHashMD5(filename): retval = 0;

'frozenset' object is not callable

自古美人都是妖i 提交于 2019-11-27 22:56:58
When I attempt to import hashlib in any context, it throws this error: File "<stdin>", line 1, in <module> File "build/bdist.macosx-10.11-intel/egg/hashlib.py", line 115, in <module> """ TypeError: 'frozenset' object is not callable Any idea how I can resolve this? I'm generating this error simply by opening up Terminal, running python and then typing import hashlib . I had the same problem yesterday, Hashlib wasn't installed and trying to install it using pip would give that error. I fixed it by installing it using easy_install instead. Also I had to install Scipy and Microsoft Visual C++

Using hashlib to compute md5 digest of a file in Python 3

て烟熏妆下的殇ゞ 提交于 2019-11-27 03:46:39
问题 With python 2.7 the following code computes the mD5 hexdigest of the content of a file. (EDIT: well, not really as answers have shown, I just thought so). import hashlib def md5sum(filename): f = open(filename, mode='rb') d = hashlib.md5() for buf in f.read(128): d.update(buf) return d.hexdigest() Now if I run that code using python3 it raise a TypeError Exception: d.update(buf) TypeError: object supporting the buffer API required I figured out that I could make that code run with both