6

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?

4
  • Do you want an actual file or a webpage? I guess if you want a file you will have to have a service on your server to send the data via http Commented Feb 6, 2018 at 11:45
  • yes, I want a text file which is on my server. Commented Feb 6, 2018 at 11:47
  • via http I am able to access the contents of the file, but I am not able to make a connection using https Commented Feb 6, 2018 at 11:51
  • Maybe change the tile to reflect the question. How to FTP via HTTPS? Commented Feb 6, 2018 at 11:53

1 Answer 1

4

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()  
Sign up to request clarification or add additional context in comments.

3 Comments

Where can I get SSL certificates?
Your server should place SSL certificate using the same certificate file. If you want to generate a simple certificate you can see stackoverflow.com/questions/8169999/…
Thank you! This was really helpful!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.