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

梦想与她 提交于 2021-02-08 10:42:21

问题


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?


回答1:


I had this error:

grammar_check.Error: http://127.0.0.1:8081:

I am not sure why you have to start server on your local machine as this piece of code does exactly that:

tool = grammar_check.LanguageTool('en-GB')

If you will have one more language_tool server running on 8081, then it will try to start server on port 8082 and if even that is busy on 8083 and then will fail (which was happening in my case).

Anyways for my error, I had to debug a lot and finally figured out that server was not able to run as my JAVA runtime environment was messed up.




回答2:


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



来源:https://stackoverflow.com/questions/45412823/python-2-7-grammar-check-1-3-1-library-http-error-400-bad-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!