#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved. @AUTHOR: ASJRD018 @NAME: langer @software: PyCharm @DATE: 2019/9/4 17:18 @Version: python3.6 @MODIFY DECORD:ansjer dev @file: CommonService.py @Contact: chanjunkai@163.com """ import hashlib from urllib.request import urlopen # 通过url获取文件md5 class CommonService: @staticmethod def get_remote_md5_sum(url, max_file_size=100 * 1024 * 1024): remote = urlopen(url) hash = hashlib.md5() total_read = 0 while True: data = remote.read(4096) total_read += 4096 if not data or total_read > max_file_size: break hash.update(data) return hash.hexdigest()