pythonpython-2.7bad-requestlanguagetool

Python 2.7 - grammar-check 1.3.1 library: HTTP Error 400: Bad Request


I am trying to use the grammar-check 1.3.1 library for Python

I have installed it using the pip commands

$ pip install --upgrade 3to2

$ pip install --upgrade language-check

I also unzipped the LanguageTool file from this link and moved it to C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check

Then I tried to run a test program

import grammar_check
tool = grammar_check.LanguageTool('en-GB')
text = 'This are bad.'
matches = tool.check(text)
len(matches)

But I got this error:

Traceback (most recent call last):
  File "grammar-checker-test.py", line 2, in <module>
    tool = grammar_check.LanguageTool('en-GB')
  File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 196, in __init__
    self._language = LanguageTag(language)
  File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 405, in __new__
    return unicode.__new__(cls, cls._normalize(tag))
  File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 426, in _normalize
    for language in get_languages())
  File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 485, in get_languages
    languages = LanguageTool._get_languages()
  File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 286, in _get_languages
    for e in cls._get_root(url, num_tries=1):
  File "C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\__init__.py", line 311, in _get_root
    raise Error(u'{}: {}'.format(cls._url, e))
grammar_check.Error: http://127.0.0.1:8081: HTTP Error 400: Bad Request

How can I solve this error?


Solution

  • The problem was that I wasn't running the LanguageTool server.

    In order to do that I have to check if I have the LanguageTool folder (its version must be < 3.3, in my case it's the 2.2) inside my grammar_check folder.

    Then using the cmd shell I have to move into this LanguageTool folder, which in my case is located in this path:

    C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_check\LanguageTool-2.2
    

    than, I have to run the server with this command

    java -cp languagetool-server.jar org.languagetool.server.HTTPServer --port 8081
    

    and voilĂ  grammar_check is working well