I need to add a scheme to urls which don't have it. I want to use the following code:
from urllib.parse import urlparse, urlunparse
url = 'example.com'
parsed = urlparse(url)
parsed = parsed._replace(scheme='https')
new_url = urlunparse(parsed)
print(new_url)
Instead of this:
https://example.com
the script is returning this:
https:///example.com
which throws and error if I try to get the url like so:
requests.get('https:///example.com')
Why is this happening and what can I do about it?
I am using:
Windows 10
Python 3.6.1
Anaconda 4.4.0