rhiever / TwitterFollowBot

A Python bot that automates several actions on Twitter, such as following users and favoriting tweets.
GNU General Public License v3.0
1.3k stars 448 forks source link

auto_unfollow_nonfollowers() crashes for certain suspended user #142

Open jackrhysider opened 6 years ago

jackrhysider commented 6 years ago

I run the following program:

from TwitterFollowBot import TwitterBot
my_bot = TwitterBot("/home/pi/tw/unfollowconfig.txt")
my_bot.sync_follows()
my_bot.auto_unfollow_nonfollowers()

And I get this error:

Unfollowed 22492607
Unfollowed 83813341
Unfollowed 907440035535847424
Unfollowed 802542516721610756
Traceback (most recent call last):
  File "unfol", line 4, in <module>
    my_bot.auto_unfollow_nonfollowers()
  File "/usr/local/lib/python2.7/dist-packages/TwitterFollowBot/__init__.py", line 404, in auto_unfollow_nonfollowers
    self.TWITTER_CONNECTION.friendships.destroy(user_id=user_id)
  File "/usr/local/lib/python2.7/dist-packages/twitter/api.py", line 308, in __call__
    return self._handle_response(req, uri, arg_data, _timeout)
  File "/usr/local/lib/python2.7/dist-packages/twitter/api.py", line 341, in _handle_response
    raise TwitterHTTPError(e, uri, self.format, arg_data)
twitter.api.TwitterHTTPError: Twitter sent status 404 for URL: 1.1/friendships/destroy.json using parameters: (oauth_consumer_key=xxxxxx2&oauth_nonce=xxxxx&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1526705448&oauth_token=xxxx&oauth_version=1.0&user_id=988034843962421248&oauth_signature=xxxxxxxx)
details: {u'errors': [{u'message': u'Sorry, that page does not exist.', u'code': 34}]}

I've tried to look up that user: https://twitter.com/intent/user?user_id=988034843962421248

But it says account suspended.

Perhaps this script can't unfollow suspended accounts? I can't figure out what username they are. Is there anyway to get the script to not try to unfollow this account using the user id??

jackrhysider commented 6 years ago

The program still crashes for certain suspended accounts. But I did manage to get past this by just adding those account IDs to the USERS_KEEP_FOLLOWING list. So the script doesn't try to unfollow that user ID anymore.

ghost commented 5 years ago

I am getting the same error, here is what I run:

from TwitterFollowBot import TwitterBot

my_bot = TwitterBot("/root/twitterfollowbot/configbot.txt")
my_bot.sync_follows()
my_bot.auto_unfollow_nonfollowers()

And here is the error:

Choosing time between 10 and 30 - waiting 30 seconds before action
Unfollowed 1071444127
Choosing time between 10 and 30 - waiting 23 seconds before action
Traceback (most recent call last):
  File "/root/twitterfollowbot/unfollow.py", line 5, in <module>
    my_bot.auto_unfollow_nonfollowers()
  File "/usr/local/lib/python2.7/dist-packages/TwitterFollowBot/__init__.py", line 404, in auto_unfollow_nonfollowers
    self.TWITTER_CONNECTION.friendships.destroy(user_id=user_id)
  File "/usr/local/lib/python2.7/dist-packages/twitter/api.py", line 308, in __call__
    return self._handle_response(req, uri, arg_data, _timeout)
  File "/usr/local/lib/python2.7/dist-packages/twitter/api.py", line 315, in _handle_response
    handle = urllib_request.urlopen(req, **kwargs)
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1241, in https_open
    context=self._context)
  File "/usr/lib/python2.7/urllib2.py", line 1198, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

The account my bot unfollowed isn't restricted or suspended, so I'm not sure whats going on.

breakfastmeansbreakfast commented 5 years ago

Hi! Looking at the last line in your log it’s a different error.

Name resolution errors are normally associated with DNS errors, try clearing your dns cache and try again.

ghost commented 5 years ago

Well thank you, that was the problem! This vps always gives me trouble with DNS, I flushed them and its working again.