Question

I am new to python and I have been making codes to scrap twitter data on python. Below are my codes:

import csv
import json
import twitter_oauth
import sys
sys.path.append("/Users/jdschnieder/Documents/Modules")
print sys.path

#gain authorization to twitter
consumer_key = 'xdbX1g21REs0MPxofJPcFw'
consumer_secret = 'c9S9YI6G3GIdjkg67ecBaCXSJDlGw4sybTv1ccnkrA'
get_oauth_obj = twitter_oauth.GetOauth(consumer_key, consumer_secret)
get_oauth_obj.get_oauth()

the error occurs at the line:

 get_oauth_obj.get_oauth()

the error message is as follows:

 ---------------------------------------------------------------------------
 Exception                                 Traceback (most recent call last)
 <ipython-input-36-5d124f99deb6> in <module>()
  --> 1 get_oauth_obj.get_oauth()

 /Users/jdschnieder/anaconda/python.app/Contents/lib/python2.7/site-packages/
 twitter_oauth-0.2.0-py2.7.egg/twitter_oauth.pyc in get_oauth(self)
    95         resp, content = client.request(_REQUEST_TOKEN_URL, "GET")
    96         if resp['status'] != '200':
 -> 97             raise Exception('Invalid response %s' % resp['status'])
    98 
    99         request_token = dict(self._parse_qsl(content))

 Exception: Invalid response 401

why is this error occurring, and what are possible solutions to the error?

thank you,

Was it helpful?

Solution

It looks like the Twitter library you're using does not support Twitter API v1.1. Instead of twitter_oauth, use one of the Python libraries listed here. For example, you can use Tweepy, following the documentation for OAuth Authentication

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top