bear / python-twitter

A Python wrapper around the Twitter API.
Apache License 2.0
3.41k stars 957 forks source link

Twitter API Call error: TwitterError({'Unknown error: {0}'.format(json_data)}) #580

Open STANAPI opened 6 years ago

STANAPI commented 6 years ago

Hi everyone,

I have encountered the below same error for the past few days. Could anyone advise on this? Thank you very much.

Erorr log below:


The Twitter Analytics API Call encountered the following exception: Traceback (most recent call last): File "C:\STB\STAN_MG_API\Twitter\twitter\api.py", line 4883, in _ParseAndCheckTwitter data = json.loads(json_data) File "C:\Python36-32\lib\json__init__.py", line 354, in loads return _default_decoder.decode(s) File "C:\Python36-32\lib\json\decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Python36-32\lib\json\decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\STB\STAN_MG_API\Twitter\tw_page_timeline.py", line 89, in extract response = api.GetStatus(i_dict['id_str']).AsDict() File "C:\STB\STAN_MG_API\Twitter\twitter\api.py", line 842, in GetStatus data = self._ParseAndCheckTwitter(resp.content.decode('utf-8')) File "C:\STB\STAN_MG_API\Twitter\twitter\api.py", line 4893, in _ParseAndCheckTwitter raise TwitterError({'Unknown error: {0}'.format(json_data)}) twitter.error.TwitterError: {'Unknown error: '}

boompig commented 4 years ago

I also see this error today (Mar 5, 2020), version 3.5. It appears that json_data is the empty string (in _ParseAndCheckTwitter), and the code is not prepared for that parameter value. I have no idea why it's the empty string, but have confirmed that it is.

boompig commented 4 years ago

Investigating further, it appears that the case where getting user's rate limit returns a 401 status code is not handled.