python-twitter
python-twitter copied to clipboard
Some TwitterErrors more verbose than others
When i try to fetch a timeline of a user that has marked the timeline private, i get a TwitterError with no status code, just a message String "Not authorized.". It is a bit tedious to match for this, as it it directly forwarded by the API from twitter. I wonder why other errors have status codes in them, making it easier to match them. Also, for this special case, Twitter has defined an error code: 179 - Sorry, you are not authorized to see this status Is this something that is in the scope of this library to change or does Twitter just send no status code?
We would need to see if Twitter is returning more information in the html or json payload when it returns an error state. if you have a test api call could you enable debugHTTP=True in your API setup - this will dump all of the http data. If the error code is present in the returned payload we could code to parse that.
Payload: { "request": "/1.1/friends/list.json", "error": "Not authorized." }
This happens only for some specific twitter ids. I got it like 20 from 20000. I have solve this issue not to break my script and to try multiple times with code below.
for i in range(5): try: friends = self.api.GetFriends( user_id=twitter_id, screen_name=None, cursor=None, count=None, total_count=total_count, skip_status=True, include_user_entities=False ) except Exception as e: print(str(e)) time.sleep(8) if friends is not None: break
Hope this helps.