一、字符串生成MD5
import hashlib
import requests
def req(url):
str = '1243456'
return hashlib.md5(str.encode(encoding='utf-8')).hexdigest()
二、本地文件生成MD5
import hashlib
import requests
def req(url):
with open('test.txt','rb') as f :
content = f.read()
return hashlib.md5(content).hexdigest()
三 、网络文件生成md5
import hashlib
import requests
def req(url):
try:
res = requests.get(url)
return hashlib.md5(res.content).hexdigest()
except:
print("下载链接有问题:%s"%url)