openstack API python - no module named version - python

I'm trying to instanciate VM on openstack using the NovaClient API in python. More precisely with mq-rabbit celery tasks.
Unfortunatly I got this error :
from novaclient import client
File "/usr/local/lib/python2.7/dist-packages/novaclient/__init__.py", line 15, in <module>
import pbr.version
ImportError: No module named version
I already tested with a simple python file and it works, my VM was created but when I try to do this throught a celery tash I got the error above...
My version is the latest python-novaclient-6.0.2, but as our servers are in version 2 I use the version 2 API.
Here is my code in my celery task, who works when I test in python shell :
loader = loading.get_plugin_loader('password')
auth = loader.load_from_options(auth_url=auth_url, username=username, password=password, project_name=tenant_name)
sess = session.Session(auth=auth)
nova = client.Client('2', session=sess) #API version and session

Seems it's the same error and this one
Basically what you need is to make sure you have pbr installed.
If you had it already, reinstalling might help
pip uninstall pbr
pip install pbr

Related

Can't connect python to looker

I've downloaded the looker_sdk for python.
Wrote a very simple program:
from looker_sdk import client, models
def test_looker():
sdk = client.setup("./looker.ini")
if __name__ == "__main__":
test_looker()
However, when I'm running it I'm getting the error:
ImportError: cannot import name 'client' from 'looker_sdk'.
I do see the models and was able to perform:
sdk = looker_sdk.init31()
what am I missing?
Thanks,
Nir.
It seems there may be a missing client.py file in looker_sdk version 0.1.3b8, or in your installation - I tested this on 0.1.3b4 and found no such issue.
I recommend that you uninstall the package and re-install the latest version from PyPI.

Getting the following TypeError: __init__() got an unexpected keyword argument 'iam_apikey'

Running this on Raspbian Buster. I upgraded as per the instructions on cloud.ibm.com api docs:
Installing collected packages: ibm-cloud-sdk-core, ibm-watson
Found existing installation: ibm-cloud-sdk-core 0.5.1
Uninstalling ibm-cloud-sdk-core-0.5.1:
Successfully uninstalled ibm-cloud-sdk-core-0.5.1
Found existing installation: ibm-watson 3.4.0
Uninstalling ibm-watson-3.4.0:
Successfully uninstalled ibm-watson-3.4.0
Successfully installed ibm-cloud-sdk-core-1.0.0 ibm-watson-4.0.1
The script looks like:
#!/usr/bin/python3
from ibm_watson import TextToSpeechV1
import json
text_to_speech = TextToSpeechV1(
iam_apikey='7XT8Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
url='https://stream.watsonplatform.net/text-to-speech/api'
)
with open('file.wav', 'wb') as audio_file:
audio_file.write(
...
Again, the code block only includes the first line. Not real helpful.
The almost identical script runs fine on Mint 18.
The actual error:
python3 watson.py
Traceback (most recent call last):
File "watson.py", line 7, in <module>
url='https://stream.watsonplatform.net/text-to-speech/api'
TypeError: __init__() got an unexpected keyword argument 'iam_apikey'
Just for good measure I attempted to connect using node.js code and I get a similar error, "missing keyword apikey"
Thanks for any help.
Jim.
In version 4, which you are now using, the TextToSpeechV1 constructor changed to accept an authenticator instead of an iam_apikey to allow additional authentication mechanisms. From the migration docs:
Before
from ibm_watson import MyService
service = MyService(
iam_apikey='{apikey}',
url='{url}'
)
After (V4.0)
from ibm_watson import MyService
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{apikey}')
service = MyService(
authenticator=authenticator
)
service.set_service_url('{url}')
In your case, MyService would be TextToSpeechV1.

ModuleNotFoundError: No module named 'flask_session'

I have a simple python file that I am trying to set up to utilize sessions, when i run the file I am receiving the error below:
ModuleNotFoundError: No module named 'flask_session'
I believe I am importing the module properly, is there anything else that I can check to set this up properly?
from flask import Flask, render_template, request, session
from flask_session import Session
app = Flask(__name__)
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)
#app.route("/", methods=["GET", "POST"])
def index():
if session.get("notes") is None:
session["notes"] = []
if request.method == "POST":
note = request.form.get("note")
session["notes"].append(note)
return render_template("index.html", notes=notes)
Here is the traceback ( most recent call last )
File "c:\python37\lib\site-packages\flask\cli.py", line 325, in __call__
Open an interactive python shell in this frameself._flush_bg_loading_exception()
File "c:\python37\lib\site-packages\flask\cli.py", line 313, in _flush_bg_loading_exception
reraise(*exc_info)
File "c:\python37\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "c:\python37\lib\site-packages\flask\cli.py", line 302, in _load_app
self._load_unlocked()
File "c:\python37\lib\site-packages\flask\cli.py", line 317, in _load_unlocked
self._app = rv = self.loader()
File "c:\python37\lib\site-packages\flask\cli.py", line 372, in load_app
app = locate_app(self, import_name, name)
File "c:\python37\lib\site-packages\flask\cli.py", line 242, in locate_app
'\n\n{tb}'.format(name=module_name, tb=traceback.format_exc())
I've first encountered this problem while doing Harvard's CS50x class. I'm using Linux and I've been using Python3, as it turns out I've installed Flask-Session for Python2.
I don't know whether it also applies to Mac but I used the following instead:
$ pip3 install flask-session
Then you can check whether it's installed with pip's freeze command. After doing this my pylint in VSCode no longer gave an error.
I got the flask_session module not found a number of times and it took me 2 hours to find a fix after thousands of attempts. Well, I too visited a number of sites looking for a solution but didn't get any. I got this error while I was learning the online course cs50 web development on edx.org by Harvard and when I read the forum discussion on reddit I saw comments where they mentioned Harvard used a special server to make it work and I felt the pain of not going to Harvard but two hours later I'm screaming because I just found a solution that's no where on the internet.
You should not use from flask_session import Session
Instead use from flask_session.__init__ import Session
I cannot explain the terminology as to why we do this here but you can private message me if you want to understand why we do this. Happy Coding!
Be sure to have the extension installed:
pip install Flask-Session
oficial page with instructions
If you get the error "ModuleNotFoundError: No module named 'werkzeug.contrib'":
pip install werkzeug==0.16.0
The latest version is the 1.0.1 but only the 0.16.0 worked.
(where I found this solution) (official page)
simply goto terminal and type pip install flask_session , wait for installation, once done you are good to go. ( Also many other solutions do not work, look for red highlighted part in image. Once installed it works properly.)
I ran into the same error.
The following worked for me.
Install the extension with the following command:
$ easy_install Flask-Session
or alternatively, if you have pip installed:
$ pip install Flask-Session
I got it for windows:
There's no the library "flask_session" (--is a directory--) in your directory ...venv\Lib\site-packages (virtual environment)
You just need copy it from C:\Users\your _user\AppData\Local\Programs\Python\Python37-32\Lib\site-packages
and then paste it in venv\Lib\site-packages or where you have installed your virtual environment. Thats it and sorry for my english, greetings from Medellin Colombia.
Try to do following command instead of all go to terminal and type
$ easy_install Flask-Session
If it shows an error,use sudo before it , If it shows any error please let me know also feel free to upvote
Install the extension first using the following command $ pip install Flask-Session. You can read more on flask-session via https://pythonhosted.org/Flask-Session/
For completeness, I will share my solution:
In my case installed everything with pip3 to make it work with python 3.7, only worked with vscode after uninstalling python 2 from the system and reopening vscode.
Are you using this library? https://pythonhosted.org/Flask-Session/
The docs suggest importing it this way: from flask.ext.session import Session

OData example not working (Python)

I'm running this code that I got from here
https://tuomur-python-odata.readthedocs.io/en/latest/#what-is-this
from odata import ODataService
url = 'http://services.odata.org/V4/Northwind/Northwind.svc/'
Service = ODataService(url, reflect_entities=True)
Order = Service.entities['Order']
query = Service.query(Order)
query = query.filter(Order.Name.startswith('Demo'))
query = query.order_by(Order.ShippedDate.desc())
for order in query:
print(order.Name)
When I run the code, it says ImportError: No module named odata. I tried using pip install odata, nothing was found. How do I install this library? I can't find any documentation on how to install it either.
Download the project from GitHub, run python setup.py install, sudo if necessary.

Import error in twilio

I am having the same problem as this thread regarding twilio-python:
twilio.rest missing from twilio python module version 2.0.8?
However I have the same problem but I have 3.3.3 installed. I still get "No module named rest" when trying to import twilio.rest.
Loading the library from stand alone python script works. So I know that pip installing the package worked.
from twilio.rest import TwilioRestClient
def main():
account = "xxxxxxxxxxxxxxxx"
token = "xxxxxxxxxxxxxxxx"
client = TwilioRestClient(account, token)
call = client.calls.create(to="+12223344",
from_="+12223344",
url="http://ironblanket.herokuapp.com/",
method="GET")
if __name__ == "__main__":
main()
but this does not work:
from twilio.rest import TwilioRestClient
def home(request):
client = TwilioRestClient(account, token)
Do you have any idea what I can try next?
I named a python file in my project twilio.py. Since that file was loaded first, then subsequent calls to load twilio would reference that file instead of the twilio library.
TLDR: just don't name your python file twilio.py
Check which versions of pip and python you are running with this command:
which -a python
which -a pip
pip needs to install to a path that your Python executable can read from. Sometimes there will be more than one version of pip like pip-2.5, pip-2.7 etc. You can find all of them by running compgen -c | grep pip. There can also be more than one version of Python, especially if you have Macports or brew or multiple versions of Python installed.
Check which version of the twilio module is installed by running this command:
$ pip freeze | grep twilio # Or pip-2.7 freeze etc.
The output should be twilio==3.3.3.
I hope that helps - please leave a comment if you have more questions.
This Worked For me : (Windows)
Python librarys are in G:\Python\Lib
(Python is installed at G:, it might be different for you)
Download Twilio from github at paste the library at >> G:\Python\Lib <<
import problem gone :)
I had the same issue and it drove me crazy. Finally I figured it out. When you get the error:
AttributeError: module 'twilio' has no attribute 'version'
Look 2 lines above and the error is telling you where it expects to find the twilio file. So I moved it from where it was to where it was asking it to be.
Installed to:
c:\users\rhuds\appdata\local\programs\python\python37-32\lib\site-packages
Moved it to:
Traceback (most recent call last):
File "", line 1, in
import twilio
File "C:\Users\rhuds\AppData\Local\Programs\Python\Python37-32\twilio.py", line 2, in
Now I can import twilio. Besides that, the only other thing I did was uninstall old versions of Python, but I don't think that really mattered.

Categories