myint / language-check

Python wrapper for LanguageTool grammar checker
https://pypi.python.org/pypi/language-check
GNU Lesser General Public License v3.0
326 stars 102 forks source link

Error: http://127.0.0.1:8081: HTTP Error 400: Bad Request #45

Closed dyllanwli closed 3 years ago

dyllanwli commented 7 years ago

Hi, I got some problem when using this tools. I followed you guild and replaced Language-Tools 3.8 to language-check, then I import language_check successfully. But when I try to call any method in language-check, it just raise the same error:

Here is for languagetools():

>>> tool = language_check.LanguageTool('en-US')
Traceback (most recent call last):
  File "/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py", line 529, in get_languages
    languages = cache['languages']
KeyError: 'languages'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py", line 310, in _get_root
    with urlopen(url, data, cls._TIMEOUT) as f:
  File "/home/jie-gd/anaconda3/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/home/jie-gd/anaconda3/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/home/jie-gd/anaconda3/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/home/jie-gd/anaconda3/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/home/jie-gd/anaconda3/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/home/jie-gd/anaconda3/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py", line 201, in __init__
    self._language = LanguageTag(language)
  File "/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py", line 453, in __new__
    return str.__new__(cls, cls._normalize(tag))
  File "/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py", line 474, in _normalize
    for language in get_languages()}
  File "/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py", line 531, in get_languages
    languages = LanguageTool._get_languages()
  File "/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py", line 291, in _get_languages
    for e in cls._get_root(url, num_tries=1):
  File "/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py", line 317, in _get_root
    raise Error('{}: {}'.format(cls._url, e))
language_check.Error: http://127.0.0.1:8081: HTTP Error 400: Bad Request

Here is for get_language():

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py in get_languages()
    528     try:
--> 529         languages = cache['languages']
    530     except KeyError:

KeyError: 'languages'

During handling of the above exception, another exception occurred:

HTTPError                                 Traceback (most recent call last)
/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py in _get_root(cls, url, data, num_tries)
    309             try:
--> 310                 with urlopen(url, data, cls._TIMEOUT) as f:
    311                     return ElementTree.parse(f).getroot()

/home/jie-gd/anaconda3/lib/python3.6/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    222         opener = _opener
--> 223     return opener.open(url, data, timeout)
    224 

/home/jie-gd/anaconda3/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout)
    531             meth = getattr(processor, meth_name)
--> 532             response = meth(req, response)
    533 

/home/jie-gd/anaconda3/lib/python3.6/urllib/request.py in http_response(self, request, response)
    641             response = self.parent.error(
--> 642                 'http', request, response, code, msg, hdrs)
    643 

/home/jie-gd/anaconda3/lib/python3.6/urllib/request.py in error(self, proto, *args)
    569             args = (dict, 'default', 'http_error_default') + orig_args
--> 570             return self._call_chain(*args)
    571 

/home/jie-gd/anaconda3/lib/python3.6/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    503             func = getattr(handler, meth_name)
--> 504             result = func(*args)
    505             if result is not None:

/home/jie-gd/anaconda3/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    649     def http_error_default(self, req, fp, code, msg, hdrs):
--> 650         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    651 

HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Error                                     Traceback (most recent call last)
<ipython-input-20-7ce33a1ca083> in <module>()
----> 1 tool = language_check.get_languages()

/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py in get_languages()
    529         languages = cache['languages']
    530     except KeyError:
--> 531         languages = LanguageTool._get_languages()
    532         cache['languages'] = languages
    533     return languages

/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py in _get_languages(cls)
    289         url = urllib.parse.urljoin(cls._url, 'Languages')
    290         languages = set()
--> 291         for e in cls._get_root(url, num_tries=1):
    292             languages.add(e.get('abbr'))
    293             languages.add(e.get('abbrWithVariant'))

/home/jie-gd/anaconda3/lib/python3.6/site-packages/language_check/__init__.py in _get_root(cls, url, data, num_tries)
    315                     cls._start_server()
    316                 if n + 1 >= num_tries:
--> 317                     raise Error('{}: {}'.format(cls._url, e))
    318 
    319     @classmethod
sergeyf commented 7 years ago

I had the same issue. Just install the latest from git instead of pip and it works.

cwlinghk commented 6 years ago

In my case, it is the new http api in languagetool. Use back languagetool 3.2 instead will solve the problem.

mr-yamraj commented 6 years ago

When I try to install it from git it gives me this error:

Could not parse Java version from """java version "10.0.1" 2018-04-17 Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode) """.

how can i remove this runtime java error.

aashish-amber-abz commented 5 years ago

I had the same issue. Just install the latest from git instead of pip and it works.

i did installed from git and is using languagetool 3.2 but is geting the same error . Kindly help

jxmorris12 commented 4 years ago

Hi! Since this project has been abandoned, I started a new fork over at https://github.com/jxmorris12/language_tool_python.

My version supports new versions of Java and LanguageTool. language-check is stuck on Java 8 and LanguageTool 3.2; latest versions are Java 14 and LanguageTool 4.9!

I'm happy to help you with your issue if you raise it over at my repository! Thanks!