Lynten / stanford-corenlp

Python wrapper for Stanford CoreNLP.
MIT License
922 stars 200 forks source link

'json.decoder.JSONDecodeError' Error #105

Open mvllwong opened 2 years ago

mvllwong commented 2 years ago

As the lastest version of Chinese language package met the 'json.decoder.JSONDecodeError', which is caused by http request error :[500], the fuction _request should be updated as(change the annotators conf) :

def _request(self, annotators=None, data=None, *args, **kwargs): if sys.version_info.major >= 3: data = data.encode('utf-8') if annotators: annotators = 'tokenize,ssplit' + ',' + annotators # NEW language package({version} > 3.9.1.1) API cmd must inintial with these two annototars:tokenize,ssplit properties = {'annotators': annotators, 'outputFormat': 'json'} params = {'properties': str(properties), 'pipelineLanguage': self.lang} if 'pattern' in kwargs: params = {"pattern": kwargs['pattern'], 'properties': str(properties), 'pipelineLanguage': self.lang}

    logging.info(params)
    r = requests.post(self.url, params=params, data=data, headers={'Connection': 'close'})
    print(self.url, r)
    r_dict = json.loads(r.text)

    return r_dict