• Geek_0dccde
    2023-01-11 来自北京
    看完第八章,但我感觉至少得看两到三遍。

    编辑回复: 如果多看几遍可以理解得更透彻,记得更牢固,也是非常幸运的一件事情😊

    共 2 条评论
    1
  • Sofia@
    2023-05-08 来自上海
    URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)> 老师,为什么我在Jupyter里面跑总是报这个错呢,重新下载了证书,指定证书路径,重新安装certifi这个库都没用,这是什么原因呢?

    作者回复: 应该是浏览器开了代理,导致请求失败,并非安装certifi库

    
    
  • Calvin
    2023-01-25 来自上海
    “发现下载地址是 HTTPS 协议的。通过协议类型,我们首先排除不支持 HTTPS 协议的库。这样可以将待使用的协议从十几个精简到三个:webbrowser、urlib、http.client。”请问老师,这里是一个个库点进去看排除嘛,还是靠标准库内的搜索功能。我用关键字https搜索了一下,匹配的信息又太多了“https://docs.python.org/zh-cn/3.10/search.html?q=https”

    作者回复: 不是的,大部分是靠经验得来的结果, 虽然Python标准库比较多, 但是结合自身的工作场景,一般只有十几个常用的,在里面再精挑细选得到的结论

    
    
  • Geek_Mike
    2023-08-09 来自云南
    import hashlib from urllib.request import urlopen import tempfile import shutil url = 'https://example.com/file_name.exe' with urlopen(url) as f1: with tempfile.NamedTemporaryFile(delete=False) as tmp_file: shutil.copyfileobj(f1, tmp_file) with open(tmp_file, 'rb') as f2: md5 = hashlib.md5() chunk = 1024 while True: data = f2.read(chunk) if not data: break md5.update(data) print(md5.hexdigest())
    
    
  • yanyu-xin
    2023-02-24 来自广东
    import hashlib from urllib.request import urlretrieve remote_url = "https://www.python.org/ftp/python/3.10.9/python-3.10.9-amd64.exe" local_file = "e:\python-3.10.9-amd64.exe" urlretrieve(remote_url, local_file) md5 = hashlib.new('md5') #创建md5对象 # 用with同时读取大文件每一行 with open(local_file, "rb") as f: for fLine in f: md5.update(fLine.readline()) print(md5.hexdigest()) #返回md5对象
    
    
  • Matthew
    2023-01-05 来自江苏
    import hashlib from urllib.request import urlretrieve def get_file_md5(file_name, blobk_size): """ 计算大文件的md5 """ m = hashlib.new('md5') #创建md5对象 with open(file_name,'rb') as fobj: while True: data = fobj.read(blobk_size) if not data: break m.update(data) #更新md5对象 return m.hexdigest() #返回md5对象 if __name__ == '__main__': remote_url = "https://www.python.org/ftp/python/3.10.9/python-3.10.9-amd64.exe" local_file = "./python-3.10.9-amd64.exe" urlretrieve(remote_url, local_file) f_md5 = get_file_md5(local_file, 10) print(f_md5)
    
    