jxmorris12 / language_tool_python

a free python grammar checker šŸ“āœ…
GNU General Public License v3.0
434 stars 64 forks source link

AttributeError: __enter__ #52

Closed cabdelahad closed 2 years ago

cabdelahad commented 2 years ago

Hi,

I recently encountered an AttributeError when trying to load the model using :

tool = language_tool_python.LanguageTool('fr')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_9928/2112106970.py in <module>
      1 import language_tool_python
      2 
----> 3 tool = language_tool_python.LanguageTool('fr')

c:\users\abel\appdata\local\programs\python\python38\lib\site-packages\language_tool_python\server.py in __init__(self, language, motherTongue, remote_server, newSpellings, new_spellings_persist)
     60             self._new_spellings = newSpellings
     61             self._register_spellings(self._new_spellings)
---> 62         self._language = LanguageTag(language, self._get_languages())
     63         self.motherTongue = motherTongue
     64         self.disabled_rules = set()

c:\users\abel\appdata\local\programs\python\python38\lib\site-packages\language_tool_python\server.py in _get_languages(self)
    187         url = urllib.parse.urljoin(self._url, 'languages')
    188         languages = set()
--> 189         for e in self._query_server(url, num_tries=1):
    190             languages.add(e.get('code'))
    191             languages.add(e.get('longCode'))

c:\users\abel\appdata\local\programs\python\python38\lib\site-packages\language_tool_python\server.py in _query_server(self, url, params, num_tries)
    207         for n in range(num_tries):
    208             try:
--> 209                 with requests.get(url, params=params, timeout=self._TIMEOUT) as response:
    210                     try:
    211                         return response.json()

AttributeError: __enter__

knowing that a few days ago everything was working perfectly !

Do you have any idea where the problem could come from ?

Tkx in advance

jxmorris12 commented 2 years ago

Hi @cabdelahad - this looks like an error with the underlying libraries. What version of requests are you using? Can you type pip show requests and paste the output here? (You might also try pip install requests --upgrade and see if that fixes the issue.)

cabdelahad commented 2 years ago

Thanks a lot, it solves my issue :)