开发者

Django get_object_or_create() not working on deployment server

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜