0
Python Question for profanity checker
iam having trouble with urlopen function please help me i am getting "httperror 400 bad request" import urllib.request def read_text(): quote = open(r"C:\Users\Raj Singh\Downloads\Documents\movie.txt") content = quote.read() print(content) quote.close() check_profanity(content) def check_profanity(content): connection = urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+"content") output = connection.read() if "true" in output: print("Profanity Alert!!!") elif "false" in output: print("Everything is fine") connection.close() read_text()
1 Answer
0
import urllib.request
import urllib.parse
def read_text():
quotes = open("C:\Check Profanity\movie_quotes.txt")
contents_of_file = quotes.read()
print(contents_of_file)
quotes.close()
check_profanity(contents_of_file)
def check_profanity(text_to_check):
encoded_text = urllib.parse.quote(text_to_check, 'utf-8')
address = "http://www.wdylike.appspot.com/?q="+encoded_text
connection = urllib.request.urlopen(address)
output = connection.read().decode('utf-8')
print(output)
connection.close()
if "true" in output:
print("Profanity Alert!")
elif "false" in output:
print("This document has no curse words!")
else:
print("Could not scan the document properly.")
read_text()