I'm having major trouble with a get_or_create call. I have it working locally absolutely fine, and the same script is working online on another site. Has anyone got an idea what's going on?
I get "IntegrityError: (1062, "Duplicate entry '2147483647' for key 'PRIMARY'")" whenever I run the script...
for tweet in TwitterSearchFeed.entries:
    if tweet.id[0:3] == 'tag':
        tweet_id = tweet.id.split(':')[2] # tweet.id[tweet.id.rindex(':')+1:] #tag:search.twitter.com,2005:10016544708
        screen_name = tweet.author.split('(')[0].strip()
        text = smart_unicode(tweet.title)
        pub_time = time.strptime(tweet.published, "%Y-%m-%dT%H:%M:%SZ") #2010-01-01T22:20:55Z
        pub_time = datetime.datetime.fromtimestamp(time.mktime(pub_time)) # UTC
        name = tweet.author.split('(')[1].split(')')[0].strip()
        # make sure tweet comes after 30 mins before kickoff
        if pub_time > (game.kickoff - datetime.timedelta(minutes=30)):
            # filter RTs
            if not text[0:3] == "RT ":
                # add or get tweet
                tweet_dict = {
                    'twitter_id': tweet_id,
                    'pub_time': pub_time,
                    'text': text,
                    'name': name,
                    'username': screen_name,
                    'game': game,
                    'atthegame': atthegame
                    }
                obj, created = Tweet.objects.get_or_create(twitter_id=tweet_id, defaults=tweet_dict)
                if created:
             开发者_JAVA百科       output += "Tweet added - %s, %s, '%s'<br />" % (tweet_id, screen_name, text)
                else:
                    output += "Tweet %s already exists<br />" % tweet_id
    else:
        output += "Tweet id error<br />" 
return HttpResponse(output)
My guess is that you suffer from this: How do I deal with this race condition in django?
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论