2

Question

How do I force requests to make HTTPS requests, even if the URL is given as 'http://...'?

Related questions

There are questions similar in title such as this one but they're not quite answering my question.

I also looked into the verify argument (link to question), but again I'm not quite sure if just setting it to True solves the issue.

Attempt

My current code just runs any URL through an assert_https function before handing it to requests.

from urllib.parse import urlparse

def assert_https(url: str) -> str:
    components = urlparse(url)
    components = components._replace(scheme='https')
    return components.geturl()
SuperStormer
  • 4,997
  • 5
  • 25
  • 35
actual_panda
  • 1,178
  • 9
  • 27
  • 1
    I would do it the way you currently are, by altering the url you ask `requests` to fetch. I don't think `verify=True` will do anything for http:// requests, it is whether to verify the certificate of https requests so will only be relevant when making https:// requests – Anentropic Sep 22 '22 at 10:47

0 Answers0