0

I am trying to validate a URL from my input's which needs to validate whether it is https or not. I see many solutions with regex, urlparser, urllib

I tried different modules in python like validator-collection

validators.url.url(value, public=False)
url('http://foobar.dk') - returns True or False
is_url('https://foobar.dk') - returns True or False

but this tells me for both http and https, I want to throw an error for any URL other than "https". Is there any module to validate only https URL's in python?

1 Answer 1

1

Can you add a second check?

if not my_url.startswith("https"):
    raise ValueError(f"URL {my_url} does not starts with https")
Sign up to request clarification or add additional context in comments.

2 Comments

I can do that, but is that the right way?
given the constraints I'm guessing it's quite alright. If you want a better solution, I'd go with urllib.parse and check for the scheme attribute.

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.