Python 2.7 - 语法检查 1.3.1 库:HTTP 错误 400:错误请求 [英] Python 2.7 - grammar-check 1.3.1 library: HTTP Error 400: Bad Request
问题描述
我正在尝试使用 Python 的 grammar-check 1.3.1
库
I am trying to use the grammar-check 1.3.1
library for Python
我已经使用 pip 命令安装了它
I have installed it using the pip commands
$ pip install --upgrade 3to2
$ pip install --upgrade language-check
我还从这个链接解压了LanguageTool文件并将其移至C:\Users\me\AppData\Roaming\Python\Python27\site-packages\grammar_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?
推荐答案
问题是我没有运行 LanguageTool 服务器.
The problem was that I wasn't running the LanguageTool server.
为了做到这一点,我必须检查我的grammar_check文件夹中是否有LanguageTool文件夹(它的版本必须<3.3,在我的例子中是2.2).
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.
然后使用 cmd shell 我必须移动到这个 LanguageTool 文件夹,在我的例子中它位于这个路径中:
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
瞧,grammar_check 运行良好
and voilà grammar_check is working well
这篇关于Python 2.7 - 语法检查 1.3.1 库:HTTP 错误 400:错误请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!