Sometimes Tweepy could trigger a Tweet Duplicate Error if the last tweet posted and the new one you are trying to post is the same or almost the same.
For example, if an artist increases his subs by 0.2 in one hour, the Bot will try to post two tweets almost the same but with a single digit changed. This could lead to that error.
To fix it we need to catch the error and continue execution without posting anything on Twitter. This way we can still continue to edit the contents of channel.csv.
If the execution is terminated due to this error, the side effect is that the channel.csv is not written with the new data and could possibly lead to more errors like this.
Traceback (most recent call last):
File "main.py", line 211, in <module>
channels = update_subscribers(response, channels)
File "main.py", line 90, in update_subscribers
subs_notify_change(channel)
File "main.py", line 101, in subs_notify_change
twitter_post("{} reached {} Million subscribers on YouTube\n@{} #music #youtube #stats".format(channel["name"], int(channel["subs"])/1000000, channel["username"]))
File "main.py", line 155, in twitter_post
api.update_status(message)
File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/tweepy/api.py", line 205, in update_status
return bind_api(
File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/tweepy/binder.py", line 253, in _call
return method.execute()
File "/opt/hostedtoolcache/Python/3.8.6/x64/lib/python3.8/site-packages/tweepy/binder.py", line 234, in execute
raise TweepError(error_msg, resp, api_code=api_error_code)
tweepy.error.TweepError: [{'code': 187, 'message': 'Status is a duplicate.'}]