如何在python 3中发出https请求

Sid*_*ath 5 python python-requests

我想使用https协议从服务器下载文件。我应该怎么做呢?这是我使用http的基本代码

response=requests.get('http://url',stream='True')

handle=open('dest_file.txt','wb')
for chunk in response.iter_content(chunk_size=512):
    if chunk:  # filter out keep-alive new chunks
        handle.write(chunk)

handle.close()  
Run Code Online (Sandbox Code Playgroud)

请求模块也可以用于https吗?

小智 4

根据http://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification

response=requests.get('https://url', stream='True', verify='your certificate.crt')

handle=open('dest_file.txt','wb')
for chunk in response.iter_content(chunk_size=512):
    if chunk:  # filter out keep-alive new chunks
        handle.write(chunk)

handle.close()  
Run Code Online (Sandbox Code Playgroud)