datamachine / twx.botapi

Unofficial Telegram Bot API Client
MIT License
238 stars 46 forks source link

Sometimes it comes not valid json #2

Closed llybin closed 9 years ago

llybin commented 9 years ago
Exception in thread Thread-4203:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "venv/lib/python3.4/site-packages/twx/botapi/botapi.py", line 759, in _async_call                                      api_response = resp.json()
  File "venv/lib/python3.4/site-packages/requests/models.py", line 819, in json
    return json.loads(self.text, **kwargs)
  File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)
llybin commented 9 years ago

I fixed a like this:

        try:                                                                                                                                                                                    
            api_response = resp.json()                                                                                                                                                          
        except ValueError:                                                                                                                                                                                 
            api_response = {'ok': False}  

can't trust anyone :)

xlopo commented 9 years ago

Adding your fix with an additional brief description, thanks!

https://github.com/datamachine/twx.botapi/commit/e669b8919d402de280257dd39e6e6fea09c5c71e