-1

So I am working on a Twitter bot and during the exceptions I run into a error that causes the program to stop. I am not to sure what is causing it.

I've been searching around trying to figure it out but have had no luck.

Any chance someone can spot the issue.

except tweepy.error.TweepError as e:
            error_code = list(e)[0][0].get('code')
            if error_code == 327:
                print('no need')

            elif error_code == 88:
                print('wait 16 minutes we have hit limit')
                time.sleep(15 * 60)

            elif error_code == 226:
                print('STOP')
                time.sleep(15 * 60)

            elif error_code == 261:
                print(' banned')
            else:
                print(str(e))
    except AttributeError as e:
            print('Something bad has happened')
    except Error as e:
            print(str(e))

the error it give me is the following:

 error_code = list(e)[0][0].get('code')
 TypeError: 'TweepError' object is not iterable

any help would be great.

pylearning
  • 41
  • 1
  • 6
  • Probably because `list(e)` is failing. Why are you converting an error to a list? – Mad Physicist Jan 12 '18 at 04:05
  • `list(Exception)` doesn't work. Are you looking at [this answer](https://stackoverflow.com/questions/17157753/get-the-error-code-from-tweepy-exception-instance)? – Patrick Haugh Jan 12 '18 at 04:06
  • Possible duplicate of [Get the error code from tweepy exception instance](https://stackoverflow.com/questions/17157753/get-the-error-code-from-tweepy-exception-instance) – Mad Physicist Jan 12 '18 at 04:08
  • Thank you for that link patrick, i;ll have a read over it now – pylearning Jan 12 '18 at 04:09

1 Answers1

2

It's helpful to post the full stack trace, but in this case it's diagnosable without.

On line 2, you call list(e), but list expects something it can iterate over to generate a list. A little Googling on this API leads me to believe what you actually want is the line

error_code = e.api_code
Fred Ross
  • 494
  • 5
  • 2
  • Amazing! you are right. I must had been doing it in a outdated way. Thank you alot for that. It is now working perfectly. – pylearning Jan 12 '18 at 04:15