python - 在没有正则表达式的情况下在 python 中验证 https URL
问题描述
我正在尝试从我的输入中验证一个 URL,该 URL 需要验证它是否为 https。我看到许多使用正则表达式、urlparser、urllib 的解决方案
我在 python 中尝试了不同的模块,比如验证器集合
validators.url.url(value, public=False)
url('http://foobar.dk') - returns True or False
is_url('https://foobar.dk') - returns True or False
但这告诉我对于 http 和 https,我想为除“https”之外的任何 URL 抛出错误。是否有任何模块可以在 python 中仅验证 https URL?
解决方案
可以加第二张支票吗?
if not my_url.startswith("https"):
raise ValueError(f"URL {my_url} does not starts with https")
推荐阅读
- css - Django SCSS,不应用弹性显示
- javascript - 打字稿选择多个键
- sharepoint - SharePoint 2019 匿名访问问题 OnPremise - 通信站点和团队站点
- swift - 来自 Apple CryptoKit 的 P256 DER 签名无法通过 OpenSSL 验证(签名无效)
- typescript - ScanCommandOutput(AttributeValue) 映射到 Typescript 对象
- javascript - 如何解决在获取请求时未显示的axios发布请求问题
- reactjs - 反应事件处理程序中引发的期望/忽略错误
- javascript - 循环后复制行
- reactjs - 如果我们验证输入何时失去焦点有什么缺点
- oauth-2.0 - 如何在两个站点之间共享登录而不传递令牌(Web-SSO)