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
http://www.wdylike.appspot.com/?q= and type in the same text, it works
fine.

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 =
urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+some_text)
    output = connection.read()
    print(output)
    connection.close()

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

Error message:
Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/Udacity/profanity_check.py",
line 29, in <module>
    check_profanity(some_text="I gave it a good shot")
  File "C:/Users/Administrator/PycharmProjects/Udacity/profanity_check.py",
line 15, in check_profanity
    connection =
urllib.request.urlopen("http://www.wdylike.appspot.com/?q="+some_text)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 472, in open
    response = meth(req, response)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 582,
in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 510, in error
    return self._call_chain(*args)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", line 444,
in _call_chain
    result = func(*args)
  File "C:\Program Files\Anaconda3\lib\urllib\request.py", 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  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to