Reputation: 113
I am trying to test oauth to access twitter using code from a course. I have a python script called twurl.py that holds this code (hidden holds the keys/tokens):
import urllib
import oauth
import hidden
def augment(url, parameters) :
secrets = hidden.oauth()
consumer = oauth.OAuthConsumer(secrets['consumer_key'], secrets['consumer_secret'])
token = oauth.OAuthToken(secrets['token_key'],secrets['token_secret'])
oauth_request = oauth.OAuthRequest.from_consumer_and_token(consumer,
token=token, http_method='GET', http_url=url, parameters=parameters)
oauth_request.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(), consumer, token)
return oauth_request.to_url()
I am calling on the augment function in another script twtest.py:
import urllib
from twurl import augment
url = augment('https://api.twitter.com/1.1/statuses/user_timeline.json',
{'screen_name': 'user', 'count': '2'} )
print url
connection = urllib.urlopen(url)
data = connection.read()
print data
headers = connection.info().dict
print headers
I am running into this error:
Traceback (most recent call last):
File "/Users/user/Desktop/python/twtest.py", line 7, in <module>
{'screen_name': 'user', 'count': '2'} )
File "/Users/user/Desktop/Python/twurl.py", line 6, in augment
secrets = hidden.oauth()
AttributeError: 'module' object has no attribute 'oauth'
This code works in an online lecture I am using to learn. Oauth was pip installed by me and I can call the dir(oauth).
What am I missing, why is oauth not being imported along with the twurl script? Even if I import oauth in twtest.py the same error occurs. Thanks!
EDIT:
Hidden module is a list of called variables:
consumer_key = 'string'
consumer_secret = 'string'
token_key = 'string'
token_secret = 'string'
Upvotes: 1
Views: 1118
Reputation: 2421
I had the same problem. I find the solution in the book *Python for Everybody page 167.
For this next sample program we will download the files twurl.py, hidden.py, oauth.py, and twitter1.py from www.py4e.com/code and put them all in a folder on your computer.
Upvotes: 1
Reputation: 1
I just came through the same problem (referring to hte twurl.py script from the Dr Chuck courses on python).
Everything worked fine when I put all the python scripts in the same folder as twurl.py (ad particularly oauth.py).
My understanding is that the twurl.py script required another script (oauth.py), and that installing new libraries (like oauth through pip installer) was not doing any changes.
Upvotes: 0