'module' object has no attribute 'Consumer' on Ubuntu
facuchaves opened this issue · comments
Hi, i have a problem with oauth2 on Ubuntu, this is my code:
import oauth2 as oauth
CONSUMER_KEY = 'ZZZ'
CONSUMER_SECRET = 'KKK'
def oauth_req(url, key, secret, http_method="GET", post_body=None, http_headers=None):
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
token = oauth.Token(key=key, secret=secret)
client = oauth.Client(consumer, token)
resp, content = client.request( url, method=http_method, body=post_body, headers=http_headers, force_auth_header=True )
return resp, content
content, home_timeline = oauth_req( 'https://api.twitter.com/1.1/statuses/home_timeline.json', 'YYY', 'XXX' )
And this is the traceback
Traceback (most recent call last):
File "/home/facundo/Escritorio/oauth2.py", line 1, in
import oauth2 as oauth
File "/home/facundo/Escritorio/oauth2.py", line 13, in
content, home_timeline = oauth_req( 'https://api.twitter.com/1.1/statuses/home_timeline.json', '163064210-ZvmxvqAAJOPwUMNqhEcIM3ODDMmpso59uX38eMMJ', 'ijRSQyku55sTNtaNh1eRzBvM2OQ59CkryQQnic1NfcHX6' )
File "/home/facundo/Escritorio/oauth2.py", line 7, in oauth_req
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
AttributeError: 'module' object has no attribute 'Consumer'
i install oauth2 with this comand "pip install oauth2".
i forget to do something ?? What is worng ??
Tranks
Hi @facuchaves can you please refactor your example using github markdown so we can better help you? I'll close this Issue if we haven't had a reply in 7 days. Thanks!
I just did a check, if you did pip install python-oauth2
then that would be your issue there. I've tried the above and I'm not getting your error on 2.7.10 sorry.
Annnnd you're issue is because Consumer is a class not a property of something... see #168.
Hi @jaitaiwan, I have the same issue on windows8, I was using python3.4 with anaconda and this issue was coming. So i installed python2.7 kernel as well and run the same code.
It was not working, the code is as follows;
def oauth_get_tweet(tid, http_method="GET", post_body='', http_headers=None):
url = 'http://api.twitter.com/1.1/statuses/show.json?id=' + tid
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
token = oauth.Token(key=ACCESS_KEY, secret=ACCESS_SECRET)
client = oauth.Client(consumer, token)
resp, content = client.request(
url,
method=http_method,
body=post_body,
headers=http_headers
)
return content
AttributeError Traceback (most recent call last)
<ipython-input-50-e54d8133b446> in <module>()
----> 1 download_tweets( fetch_list, user_params['rawDir'] )
<ipython-input-45-e2ec58e04190> in download_tweets(fetch_list, raw_dir)
114
115 # pull data
--> 116 data = oauth_get_tweet(item[2])
117 with open(raw_dir + item[2] + '.json', 'wb') as outfile:
118 json.dump(data, outfile)
<ipython-input-45-e2ec58e04190> in oauth_get_tweet(tid, http_method, post_body, http_headers)
80 http_headers=None):
81 url = 'http://api.twitter.com/1.1/statuses/show.json?id=' + tid
---> 82 consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
83 token = oauth.Token(key=ACCESS_KEY, secret=ACCESS_SECRET)
84 client = oauth.Client(consumer, token)
AttributeError: 'module' object has no attribute 'Consumer'
Hey @emarshah, did you run pip install python-oauth2
? Because the correct command to run is pip install oauth2
. I think you'll find that's the issue. python-oauth2 installs as oauth2 so you'll have to run pip uninstall oauth2
.
The way I suggested was pip install oauth2
... Not python-oauth2
Oh... I totally missed it,
It's giving me following error today;
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\a>pip install oauth2
You are using pip version 7.0.3, however version 7.1.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' comm
and.
Collecting oauth2
Downloading oauth2-1.5.211.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "C:\Users\a\AppData\Local\Temp\pip-build-x0s31_87\oauth2\setup.py
", line 18
print "unable to find version in %s" % (VERSIONFILE,)
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\ammar\Ap
pData\Local\Temp\pip-build-x0s31_87\oauth2
What Python version?
On Sun, 9 Aug 2015 00:43 Ammar Hassan notifications@github.com wrote:
Oh... I totally missed it,
It's giving me following error today;
Microsoft Windows Version 6.3.9600 2013 Microsoft Corporation. All rights reserved.
C:\Users\a>pip install oauth2
You are using pip version 7.0.3, however version 7.1.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' comm
and.
Collecting oauth2
Downloading oauth2-1.5.211.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 20, in
File "C:\Users\a\AppData\Local\Temp\pip-build-x0s31_87\oauth2\setup.py
", line 18
print "unable to find version in %s" % (VERSIONFILE,)
^
SyntaxError: invalid syntax----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\ammar\Ap
pData\Local\Temp\pip-build-x0s31_87\oauth2—
Reply to this email directly or view it on GitHub
#171 (comment)
.