Error Code: Duplicate Tweet or Twitter Refusal: [{u'message': u'Status is a duplicate.'. u'code': 187}]


Hello, I am receiving the following error code:

Error Code: Duplicate Tweet or Twitter Refusal: [{u’message’: u’Status is a duplicate.’. u’code’: 187}]

I am working on the project posted at:

Here is the code that I am working with in particular (with my twitter credentials omitted). You will notice a few modifications:

import twitter
import time
import grovepi
import math

# Connections
sound_sensor = 0        # port A0
light_sensor = 1        # port A1
temperature_sensor = 2  # port D2
led = 3                 # port D3

intro_str = "The Batcave's"

# Connect to Twitter
api = twitter.Api(
    consumer_key=' ',
    consumer_secret=' ',
    access_token_key=' ',
    access_token_secret=' '

grovepi.analogWrite(led,255)  #turn led to max to show readiness

while True:

    # Error handling in case of problems communicating with the GrovePi

        # Get value from light sensor
        light_intensity = grovepi.analogRead(light_sensor)

        # Give PWM output to LED

        # Get sound level
        sound_level = grovepi.analogRead(sound_sensor)


        # Get value from temperature sensor
        [t,h] = grovepi.dht(temperature_sensor,0)
        t = ((t * 9) / 5.0) + 32
        # Post a tweet
        out_str ="%s Temp: %d F, Humidity: %d, Light: %d, Sound: %d" %(intro_str,t,h,light_intensity/10,sound_level)
        print (out_str)
    except IOError:
    except KeyboardInterrupt:
    except Exception as e:
        print("Duplicate Tweet or Twitter Refusal: {}".format(e))


Any thoughts on what is causing this error? I would guess it is because the code is tweeting too often. I had previously posted about trying to lower the tweeting frequency, see here: changing Celsius to Fahrenheit and changing frequency of tweet, and it was suggested that I add the <time.sleep(3600)> code to the last line, but that doesn’t seem to have solved the problem.


Twitter is telling you that you cannot post a duplicate tweet. So it seems at one point in the past you tweeted the same data. Best way around that one is to add the date and time to your tweet. Then it’s no longer a duplicate tweet as the timestamp will be changed.

Hope this helps,


Thanks Cleo. Any tips on what and where to insert time and datestamp code?