# 文件下载方法 from urllib.request import urlretrieve import requests # 第一 urlimage = 'https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz' urlretrieve(urlimage, "logo.tar.xz") #第二 ir = requests.get(urlimage, stream=True) print (ir.status_code) if ir.status_code == 200: with open('logo2.tar.xz', 'wb') as f: for chunk in ir: f.write(chunk) #第三 ir = requests.get(urlimage) print (ir.status_code) if ir.status_code == 200: with open('logo3.tar.xz', 'wb') as f: f.write(ir.content)