Use HTTP if no protocol is included in URL (fixes #22)

This commit is contained in:
Florian Bach 2022-05-11 06:47:09 +02:00
parent b2b88abd06
commit 137fc82fa8
1 changed files with 8 additions and 0 deletions

View File

@ -319,6 +319,14 @@ def sendPOSTHTTPRequest(URL, document, type, returnRC = False):
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
# Make sure URL has a protocol
# Some vendors (see issue #22) apparently don't include "http://" in some of their URLs.
# Python returns an error when it encounters such a URL, so just add that prefix if it's not present.
if not "://" in URL:
print("Provider is using malformed URL %s, fixing." % (URL))
URL = "http://" + URL
req = ulib.Request(url=URL, headers=headers, data=document)
try:
handler = ulib.urlopen(req, context=ctx)