I want to download a file from my server using the https protocol. How should I go about doing this? This is my basic code with 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()
can the requests module be used for https as well?
Making a Request Python requests module has several built-in methods to make Http requests to specified URI using GET, POST, PUT, PATCH or HEAD requests. A Http request is meant to either retrieve data from a specified URI or to push data to a server. It works as a request-response protocol between a client and a server.
If you need a refresher, then check out Socket Programming in Python (Guide). As protocols go, HTTP is one of the simpler ones. It was designed to send content over the Internet, like HTML, videos, images, and so on. This is done with an HTTP request and response.
A Http request is meant to either retrieve data from a specified URI or to push data to a server. It works as a request-response protocol between a client and a server.
Chrome: Go to Settings > Advanced > Privacy and security > Manage certificates > Authorities. Firefox: Go to Settings > Preferences > Privacy & Security > View Certificates > Authorities. This covers the infrastructure required to create Python HTTPS applications in the real world. In the next section, you’ll apply these concepts to your own code.
According to 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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With