c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
Python

Check hostname requires server hostname - SOLVED

| | python
I got the following error in python project "check hostname requires server hostname" 
CODE:
    parsed_url = urlparse(domain)

domain = parsed_url.netloc

context = ssl.create_default_context()
conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=domain)


conn.connect((domain, 443))

To avoid this error, you can normalize the input to extract the correct domain name.
UPDATED CODE:
    parsed_url = urlparse(domain if domain.startswith(('http://','https://')) else 'http://'+ domain)

domain = parsed_url.netloc

context = ssl.create_default_context()
conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=domain)


conn.connect((domain, 443))