Reputation: 467
when I'm trying open a website with urllib library I'm getting the error. I'm not getting why this error occurs? currently I'm using python 3.6 version. Is this problem with version?
url = 'https://example.com'
html = urllib.request.urlopen(url).read().decode('utf-8')
text = get_text(html)
data = text.split()
print(data)
Upvotes: 0
Views: 7764
Reputation: 467
I have solved it by this code:
import ssl
ssl.match_hostname = lambda cert, hostname: True
Example:
import ssl
ssl.match_hostname = lambda cert, hostname: True
url = 'https://example.com'
html = urllib.request.urlopen(url).read().decode('utf-8')
text = get_text(html)
data = text.split()
print(data)
Upvotes: 2
Reputation: 563
This error occurs when the common name of your SSL/TLS Certificate does not match the domain name of you site. Try changing the domain name of your site to exampleServer.Com and see if it works. Otherwise, you will have to write custom logic to ignore name mismatch error.
Upvotes: 1