401 Error Twitter API

This is the place for queries that don't fit in any of the other categories.

401 Error Twitter API

Postby eddienash » Sat Aug 02, 2014 8:32 am

I'm trying to learn social web mining from this python book entitled Mining the social web, and I'm getting on the first few functions, here's my output:
Code: Select all
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import twitter
>>> CONSUMER_KEY = 'OqzcxXgpS5QV2Tk2AfmQ6ZQkN'
>>> CONSUMER_SECRET = 'BXOP7eRBb1mbWL2PqBlHb3umkNc6sOqVu5WOt9ps8Qrid9mjVa'
>>> OAUTH_TOKEN = '268110347-D4e2FieLOvYXW6kec53FNRnf6U0W5crYMTo35g4z'
>>> OAUTH_TOKEN_SECRET = 'hA7TkrHaFIcXm7MItti6zqtekdMMR4CTTnKykZGprvCpD'
>>> twitter_api = twitter.Twitter(auth=auth)
>>> print twitter_api
<twitter.api.Twitter object at 0x7f09c8f822d0>
>>> WORLD_WOE_ID = 1
>>> US_WOE_ID = 23424977
>>> world_trends = twitter_api.trends.place(_id=WORLD_WOE_ID)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/twitter/api.py", line 245, in __call__
    return self._handle_response(req, uri, arg_data, _timeout)
  File "/usr/local/lib/python2.7/dist-packages/twitter/api.py", line 276, in _handle_response
    raise TwitterHTTPError(e, uri, self.format, arg_data)
twitter.api.TwitterHTTPError: Twitter sent status 401 for URL: 1.1/trends/place.json using parameters: (id=1&oauth_consumer_key=268110347-D4e2FieLOvYXW6kec53FNRnf6U0W5crYMTo35g4z&oauth_nonce=1757183773199297987&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1406967280&oauth_token=OqzcxXgpS5QV2Tk2AfmQ6ZQkN&oauth_version=1.0&oauth_signature=n71vwEWWTMVKe9%2B3hQqzEdYUd8Y%3D)
details: {"errors":[{"message":"Invalid or expired token","code":89}]}

What seems to be the problem here, how can I use this function correctly?
Last edited by Yoriz on Sat Aug 02, 2014 10:28 am, edited 1 time in total.
Reason: First post lock.
Posts: 2
Joined: Sat Aug 02, 2014 6:24 am

Re: 401 Error Twitter API

Postby Yoriz » Sat Aug 02, 2014 10:28 am

Welcome to the forum, Please read the new users read this link in my signature.
Due to the reasons discussed here we will be moving to python-forum.io/ on October 1 2016
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Posts: 1672
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: 401 Error Twitter API

Postby snippsat » Sat Aug 02, 2014 12:52 pm

401 means that there is a problem with authentication you have given.
It complain on your CONSUMER_KEY,that's it Invalid or expired.
You have been at "dev.twitter.com/apps/new" and gotten correct log-in info?
We will be moving to python-forum.io on October 1 2016
User avatar
Posts: 1251
Joined: Thu Feb 21, 2013 12:04 am

Re: 401 Error Twitter API

Postby eddienash » Sat Aug 02, 2014 7:51 pm

Yes, I have gotten all the login info, here's my application info if you want to check it out: https://dev.twitter.com/apps/6579444/oauth
I tried to regenerate the keys and I guess the new keys are invalid or expired as well. How is this happening and what can I do to fix it?
Posts: 2
Joined: Sat Aug 02, 2014 6:24 am

Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 8 guests