JSONDecodeError

  1. 使用ptyhon第三方库stanfordcorenlp中pos_tag()方法时,%(百分号)导致JSONDecodeError。
    print(nlp.pos_tag('this is a apple'))  # [('this', 'DT'), ('is', 'VBZ'), ('a', 'DT'), ('apple', 'NN')]
    print(nlp.pos_tag('this is a %'))
    
    JSONDecodeError                           Traceback (most recent call last)
    <ipython-input-83-4a86c2360061> in <module>
    ----> 1 nlp.pos_tag('this is a %')
    
    c:\users\luyiheng\anaconda3\lib\site-packages\stanfordcorenlp\corenlp.py in pos_tag(self, sentence)
      183 
      184     def pos_tag(self, sentence):
    --> 185         r_dict = self._request('pos', sentence)
      186         words = []
      187         tags = []
    
    c:\users\luyiheng\anaconda3\lib\site-packages\stanfordcorenlp\corenlp.py in _request(self, annotators, data, *args, **kwargs)
      237         logging.info(params)
      238         r = requests.post(self.url, params=params, data=data, headers={'Connection': 'close'})
    --> 239         r_dict = json.loads(r.text)
      240 
      241         return r_dict
    
    c:\users\luyiheng\anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
      317             parse_int is None and parse_float is None and
      318             parse_constant is None and object_pairs_hook is None and not kw):
    --> 319         return _default_decoder.decode(s)
      320     if cls is None:
      321         cls = JSONDecoder
    
    c:\users\luyiheng\anaconda3\lib\json\decoder.py in decode(self, s, _w)
      337 
      338         """
    --> 339         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      340         end = _w(s, end).end()
      341         if end != len(s):
    
    c:\users\luyiheng\anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
      355             obj, end = self.scan_once(s, idx)
      356         except StopIteration as err:
    --> 357             raise JSONDecodeError("Expecting value", s, err.value) from None
      358         return obj, end
    
    JSONDecodeError: Expecting value: line 1 column 1 (char 0)
    
posted @ 2020-12-01 14:46  lyiheng  阅读(477)  评论(3)    收藏  举报