Search code examples
pythonpython-3.xprofanity

CertificateError: hostname 'www.wdylike.appspot.com' doesn't match


I am doing the udacity course on learning python. Basically, this project is supposed to check for profanity in a file. We use the website "https://wdylike.appspot.com/?q=" to do this. The website checks for profanity and prints a Boolean value if there is or is not profanity. Unfortunately, they taught the course in python 2.7 while I have python 3.5 and there are some changes. So, I am turning to you. Whenever I run the code below, I get an error. I will show the exact error below the code.

import urllib.request as urlr

def read_text():
    quotes = open(r"C:\Users\setup\Documents\Sophomore Year\Math\Code_Help.txt")
    contents_of_file = quotes.read()
    print(contents_of_file)
    quotes.close()
    check_profanity(contents_of_file)

def check_profanity(text_to_check):
    print(text_to_check)
    link = ("https://www.wdylike.appspot.com/?q=")
    connection = urlr.urlopen (link + text_to_check)
    output = connection.read()
    print(output)
    connection.close()

read_text()

The error is:

CertificateError: hostname 'www.wdylike.appspot.com' doesn't match either of '*.appspot-preview.com', '*.appspot.com', '*.thinkwithgoogle.com', '*.withgoogle.com', '*.withyoutube.com', 'appspot-preview.com', 'appspot.com', 'thinkwithgoogle.com', 'withgoogle.com', 'withyoutube.com'

ADDITIONAL INFO: The file you see in (r"C:\Users\setup\Documents\Sophomore Year\Math\Code_Help.txt") is simply a text file with the word "ass" in it so as to trigger the profanity detector.

Thanks for the help.


Solution

  • You get the error message CertificateError: hostname 'www.wdylike.appspot.com' doesn't match either of '*.appspot-preview.com', '*.appspot.com', '*.thinkwithgoogle.com', '*.withgoogle.com', '*.withyoutube.com', 'appspot-preview.com', 'appspot.com', 'thinkwithgoogle.com', 'withgoogle.com', 'withyoutube.com'

    If you read it carefully, you'll see that it's nothing wrong with your code. It simply says that the url (www.wdylike.appspot.com) does not match anything the certificate is valid for. A certificate must match the url. Try with different urls.