0
connection = urllib.request.urlopen("http://www.wdyl.com/profanity?q=" + text_to_check)

I don't know why but the code above is not working in python 3.5 and after several hours of searching i yet to find any answer for that. What i want to do is adding text_to_check string in the end of url

The error i'm receiving is:

raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request
4
  • 3
    "is not working" is about the most useless definition of a problem. Please explain what you get exactly. Commented Jan 7, 2016 at 12:34
  • 1
    i edited my question. If i remove + text_to_check part, the url alone is working without any error or issue Commented Jan 7, 2016 at 12:36
  • 1
    What is your text_to_check when it fails? Commented Jan 7, 2016 at 12:37
  • 1
    it's full of text from a .txt file. I can print it there is no issue there. Commented Jan 7, 2016 at 12:38

1 Answer 1

1

The problem is your text_to_check.

Try this:

query = urllib.parse.urlencode({'q': text_to_check})
urllib.request.urlopen("http://www.wdyl.com/profanity?" + query)

and print the query variable to see what has to happen with your "full of text from a .txt file" in order to work correctly as a URL.

Sign up to request clarification or add additional context in comments.

2 Comments

it worked thank you! but i did not understand the code. I searched a lot but none of the solutions provided is similar to this approach
@fuzunspm - you can also have a look at requests, which may shorten the number of methods you will need: docs.python-requests.org/en/latest/user/quickstart/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.