Dear tutors,

I have written below function to open the profanity check url and then
to check for profanity in some text. When I go to the url and type in the same text, it works

I am using Microsoft OS X and Python 3.5.2 Interpreter with Pycharm
Community Edition.

import urllib.request

def check_profanity(some_text):
    # check text for a curse word
    connection =
    output =

check_profanity(some_text="I gave it a good shot")

Error message:
Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/Udacity/",
line 29, in <module>
    check_profanity(some_text="I gave it a good shot")
  File "C:/Users/Administrator/PycharmProjects/Udacity/",
line 15, in check_profanity
    connection =
  File "C:\Program Files\Anaconda3\lib\urllib\", line 163, in urlopen
    return, data, timeout)
  File "C:\Program Files\Anaconda3\lib\urllib\", line 472, in open
    response = meth(req, response)
  File "C:\Program Files\Anaconda3\lib\urllib\", line 582,
in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Program Files\Anaconda3\lib\urllib\", line 510, in error
    return self._call_chain(*args)
  File "C:\Program Files\Anaconda3\lib\urllib\", line 444,
in _call_chain
    result = func(*args)
  File "C:\Program Files\Anaconda3\lib\urllib\", line 590,
in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

Process finished with exit code 1

However when I run the code it just says Bad Request. I tried to read
into the traceback message but it refers not only to my file but the
urllib function itself too and I can't understand.

Please kindly help me guide to debug the code.

Thank you,
Amy L
Tutor maillist  -
To unsubscribe or change subscription options:

Reply via email to