AttributeError: 'module' object has no attribute 'Api' - python

I have written some basic Python code to try authenticate my credentials on twitter:
import twitter
api = twitter.Api(consumer_key='',
consumer_secret='',
access_token_key='',
access_token_secret='')
But I receive the following error message when doing so:
Traceback (most recent call last):
File "C:\Python33\nettest.py", line 3, in <module>
api = twitter.Api(consumer_key='',
AttributeError: 'module' object has no attribute 'Api'
Can anyone see what I am doing wrong? I have tried variations on this code but they all seem to fall down with the api part of the twitter 1.14.2 that i am using. i have installed this module via pip 3.3 to my python 3.3 directory. when i look in lib>site_packages>twitter i can see that there is a module installed called api. I'm really not sure what is going wrong as this should seemingly be a simple piece of code to run.
Any ideas?

simply uninstall twitter sudo pip uninstall twitter
Now install python-twiiter sudo pip install python-twitter... and it works..

If you were using the python-twitter You have a local file named twitter.py Rename it to twitterhelper.py or some other name and it should fix your problem. This was what fixed it for me.

Save your python file with any name other than twitter.py.

Related

python gTTS RuntimeError: Unable to get language list: 'NoneType' object is not subscriptable

Pre
I have seen questions about this kind of error , but it was not related with gTTS.
I use gTTS module.One day,this error suddenly happened.Yes,I have never handled these codes from the time of importing it.Until yesterday,this error didn't happen.
It happened when I excute this code:
Code
sounditems = [i for i in gtts.lang.tts_langs().values()]
Error
RuntimeError: Unable to get language list: 'NoneType' object is not subscriptable
In [1]: import gtts
In [2]: gtts.lang
Out[2]: <module 'gtts.lang' from 'C:\\Anaconda3\\lib\\site-packages\\gtts\\lang.py'>
In [3]: gtts.lang.tts_langs()
Traceback (most recent call last):
File "<ipython-input-3-53b538afe087>", line 1, in <module>
gtts.lang.tts_langs()
File "C:\Anaconda3\lib\site-packages\gtts\lang.py", line 41, in tts_langs
raise RuntimeError("Unable to get language list: %s" % str(e))
RuntimeError: Unable to get language list: 'NoneType' object is not subscriptable
gTTS version
Editor
In [7]: spyder.version_info
Out[7]: (3, 2, 8)
language
python 3.6.5
After search
I investigated in gTTS lang module.I thought it failes to get imformation from Google.Perhaps,it may not be the problem on the client side.
Added
After researching the lang.py module,I found out the source of error was from its _fetch_langs() function & it seems to have failed to execute soup.find(src=re.compile(JS_FILE))['src'].
--result
--long html code--
Try to update your gTTS module with : "pip3 install -U gTTS" in your virtual environment...
Upgrading solved it for me, but had to force a reinstall
pip install --upgrade --force-reinstall gtts
gTTS 2.0.3 is already released.
I reinstalled gTTS module by following John D. and I updated lang.py.
I rewrote my original code from
gtts.lang.tts_langs()
to
gtts.tts.tts_langs()
I could solve the problem.
This is not the mirrored answer for my question,but I'm very satisfied.
It seems that gtts module can be updated in the future and is under development now.
I have no reason for persisting to gTTS 2.0.1

PyPI Module not working

So today i started working on a simple python module, but i cant make it work.
the module itself works, but when i have uploaded it to PyPI and i then install it using Pip, it wont work.
Please notice that it is built for python-2.7
The source code can be seen here:
https://github.com/1m0r74l17y/FortyTwo
and it can be downloaded using:
sudo pip install FortyTwo
whenever i try to run a test program like this:
from FortyTwo import *
FortyTwo.nope()
It just gives me an error:
Traceback (most recent call last):
File "test.py", line 3, in
FortyTwo.nope()
AttributeError: 'module' object has no attribute 'fortytwo'
I would really appreciate any help, as it might lead me onto what i have to do to fix the problem.
You would need to do the following.
from FortyTwo import fortytwo
fortytwo.nope()
If you want to call nope directly from FortyTwo you would need to import that function in __init__.py.
e.g.
from FortyTwo.fortytwo import nope
def Start():
"""No Clue what to add here"""
What if you do
from FortyTwo import fortytwo
fortytwo.nope()
* credits to eandersson.

redis-py AttributeError: 'module' object has no attribute

I installed redis-py on CentOS and Ubuntu. On both I get the same error when trying to access it.
redis-py AttributeError: 'module' object has no attribute
If I use the python prompt in the same directory as the source this will work:
>>> import redis
>>> r = redis.Redis(host='localhost', port=6379, db=0)
but if I change directories it will give the error.
>>> import redis
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "redis.py", line 4, in <module>
print redis.__version__
AttributeError: 'module' object has no attribute '__version__'
Trying with a .py script always gives the error. Any idea what I'm doing wrong, and how to fix it. Probably a newbie Python thing...
You're naming a module you're working on redis.py and Python is importing that instead of the real redis module. Don't do that, or change sys.path to make sure the current working directory is last rather than first in the lists of directories to search.
i have this error in tornado and it was because i install redis on python 2.7 and install in python3 too , i uninstall redis from python2.7 and re_install in python3 and solve the Problem!

No module named auth error in python web.py

I am using the Python web.py framework to design a small web application.
As indicated in the tutorial, when working with authorization I tried the following in the
Python interpreter:
In [10]: import web
In [11]: from web.contrib.auth import DBAuth
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/home/local/user/python_webcode/<ipython console> in <module>()
ImportError: No module named auth
But I am getting the above error. Can anyone please let me know how to solve this error and explain why it is happening?
It looks like you do not have the auth module installed. I have assumed that the auth module you are trying to use the one at http://jpscaletti.com/webpy_auth/.
You've not indicated whether you installed web.py via easy_install or by running setup.py after downloading a tarball. In either case, I'd recommend that you:
Locate the web.py install folder
Download the auth module from the link above and extract the contents into the contrib/ folder of the web.py install folder

Why can't I send tweet from Python?

import twitter
api = twitter.Api(consumer_key=' ',
consumer_secret=' ',
access_token_key=' ',
access_token_secret=' ')
friends=api.PostUpdate("First Tweet from PYTHON APP ")
I have done everything as said at http://abhi74k.wordpress.com/2010/12/21/tweeting-from-python/ but when I full inside it and press enter, nothing happens. Can you help me about that?
Ok it is because of that I couldn't download python-twitter API correctly. It gives me this error when I try to follow those steps:
figen#figen-Satellite-A350:~/Downloads/python-twitter-0.8.2$ python setup.py install
running install
running build
running build_py
running install_lib
copying build/lib.linux-x86_64-2.7/twitter.py -> /usr/local/lib/python2.7/dist-packages
error: /usr/local/lib/python2.7/dist-packages/twitter.py: Permission denied
http://code.google.com/p/python-twitter/
Ok I installed setup.py but now it gives this error:
figen#figen-Satellite-A350:~/Downloads/python-twitter-0.8.2$ python twitter_test.py
Traceback (most recent call last):
File "twitter_test.py", line 29, in <module>
import twitter
File "/home/figen/Downloads/python-twitter-0.8.2/twitter.py", line 65, in <module>
import oauth2 as oauth
ImportError: No module named oauth2
Now it says twitter module doesn't have the module. How to get it?
api = twitter.Api(consumer_key='removed',
consumer_secret='removed',
access_token_key='removed',
access_token_secret='removed')
friends=api.PostUpdate("If you see this,I managed to send my first tweet from Python Shell. Yay! =)")
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
api = twitter.Api(consumer_key='removed for security=)',
AttributeError: 'module' object has no attribute 'Api'
There are several things causing your problem.
1) The permission denied error (error: /usr/local/lib/python2.7/dist-packages/twitter.py: Permission denied) is because you do not have administrator privileges. Try sudo python setup.py install
2) You need to install the missing dependencies (i.e. oauth2) you can get oauth2 from here http://github.com/simplegeo/python-oauth2 make sure you have the other dependencies needed which are SimpleJson and HTTPLib2. You can find more details on this information on the python-twitter-api site.
Hope this solves it!
You need to install twitter which include Api . http://code.google.com/p/python-twitter/downloads/detail?name=python-twitter-0.8.2.tar.gz this version contain Api .

Categories