Python获取URL图片文件的哈希值 hash

pip install Pillow

 

import hashlib
from io import BytesIO

def get_hash(file):
    """
    :param bytes file:
    :return:
    """
    md5hash = hashlib.md5(Image.open(file).tobytes())
    return md5hash.hexdigest()


url = 'URL'
r = requests.get(url, allow_redirects=True, stream=True)
print(get_hash(BytesIO(r.content)))

 

posted @ 2023-01-10 15:04  _迷途  阅读(322)  评论(0编辑  收藏  举报