'status', '401 Unauthorized: Failed to validate oauth signature and token


Hey Guys,
I am using oauth.py that is in my /usr/share/pyshared/oauth/ directory. (I think it comes with python or I happened to installed it somehow.)
I am trying to get request token and using following code

consumer = oauth.OAuthConsumer(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET)
    signature_method_plaintext = oauth.OAuthSignatureMethod_PLAINTEXT()
    signature_method_hmac_sha1 = oauth.OAuthSignatureMethod_HMAC_SHA1()
    # '* Obtain a request token ...'
    oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer, http_method='POST', callback=settings.CALLBACK_URL, http_url=settings.TWITTER_REQUEST_TOKEN_URL)
    oauth_request.sign_request(signature_method_hmac_sha1, consumer, None)
    connection = httplib.HTTPConnection("api.twitter.com")
    req_header = oauth_request.to_header()
    #print "req_header :  "
    #print req_header
    connection.request('POST', settings.TWITTER_REQUEST_TOKEN_URL,headers=req_header)
    response = connection.getresponse()
    resp_headers = response.getheaders()
    print resp_headers
    txt = response.read()
    print txt

But I am getting error. I checked on net and there were a lot of posts suggesting that my server time might not be in sync with twitter’s time. I am developing the app on my machine ( and my time is correct. I verified that by matching my system’s time with that of received in response header from twitter. I am working in India, so I converted my IST time to GMT time to compare the dates.

Response header received:

[(‘status’, ‘401 Unauthorized’), (‘content-length’, ‘44’), (‘x-transaction’, ‘1db4f7da3c3d912a’), (‘set-cookie’, ‘k=; path=/; expires=Sat, 12-May-12 07:40:47 GMT; domain=.twitter.com, guest_id=v1%3A13362036470935394; domain=.twitter.com; path=/; expires=Mon, 05-May-2014 19:40:47 GMT, _twitter_sess=BAh7CCIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoHaWQiJTQzMWE3OWYyMzA4YTFkNjQxZTA2Yzc4%250AZmUzOTU5NzFhOg9jcmVhdGVkX2F0bCsIdpjxGzcB–0fc84b12eac8b8fa8b26233339553ea010d9e386; domain=.twitter.com; path=/; HttpOnly’), (‘expires’, ‘Tue, 31 Mar 1981 05:00:00 GMT’), (‘x-mid’, ‘e635161d25ee67df35584ea31a82ad95c2697b2f’), (‘server’, ‘tfe’), (‘last-modified’, ‘Sat, 05 May 2012 07:40:47 GMT’), (‘x-runtime’, ‘0.01669’), (‘pragma’, ‘no-cache’), (‘cache-control’, ‘no-cache, no-store, must-revalidate, pre-check=0, post-check=0’), (‘date’, ‘Sat, 05 May 2012 07:40:47 GMT’), (‘x-frame-options’, ‘SAMEORIGIN’), (‘content-type’, ‘text/html; charset=utf-8’), (‘vary’, ‘Accept-Encoding’)]

response.read() gives me following:
Failed to validate oauth signature and token