How to use senlinclient with keystone session - openstack

How to use senlinclient with keystone session? Can anyone give me an example? Thanks.
from keystoneauth1 import session
from keystoneauth1.identity import v3
from senlinclient.client import Client as senlinClient
def get_senlin_client_by_session(session):
return senlinClient(api_ver=1, session=session)
admin_auth = v3.Password(username='admin',
password='xxxxxx',
auth_url='http://vip:5000/v3',
project_name='admin',
user_domain_name='Default',
project_domain_name='Default'
)
session = session.Session(auth=admin_auth)
senlin_client = get_senlin_client_by_session(session)
print(senlin_client)
I tried the above example, but the following error will be reported.
File "/usr/lib/python2.7/site-packages/senlinclient/client.py", line 23, in Client
return cls(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/senlinclient/v1/client.py", line 28, in __init__
self.service = self.conn.cluster
File "/usr/lib/python2.7/site-packages/openstack/service_description.py", line 95, in __get__
allow_version_hack=True,
File "/usr/lib/python2.7/site-packages/openstack/config/cloud_region.py", line 457, in get_session_client
session=self.get_session(),
File "/usr/lib/python2.7/site-packages/openstack/config/cloud_region.py", line 324, in get_session
"Problem with auth parameters")
openstack.exceptions.ConfigException: Problem with auth parameters

The problem has been solved.
openstack rocky uses python2-senlinclient-1.8.0-1.el7.noarch and python2-openstacksdk-0.17.3-1.el7.noarch. I upgraded python2-senlinclient to version 1.9.0 and the problem was solved.

Related

How to deploy a FastAPI endpoint using pythonanywhere?

I have been trying to deploy EasyOCR (it's fine if it works on CPU) with FastAPI endpoints such that anyone can use it via https POST request. It runs fine on my local host but when I have been facing challenges in deploying it using pythonanywhere. I added the additional requirements like pip install easyocr, pip install python-multipart==0.0.5.
The following is my code-
import io
import logging
import re
from fastapi import FastAPI, APIRouter, Request, File, UploadFile
from fastapi.responses import FileResponse, StreamingResponse
import easyocr
import PIL
from PIL import Image, ImageOps
import numpy
app = FastAPI()
router = APIRouter()
ocr = easyocr.Reader(["en"])
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("ocr")
#app.get("/")
async def root():
return {"message": "Hello World"}
#app.post("/ocr")
async def do_ocr(request: Request, file: UploadFile = File(...)):
if file is not None:
imgFile = numpy.array(PIL.Image.open(file.file).convert("RGB"))
res = ocr.readtext(imgFile)
# return array of strings
return [item[1] for item in res]
return {"error": "missing file"}
app.include_router(router)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app)
I am getting the error in the logs-
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/somyatomar15/main.py", line 82, in <module>
uvicorn.run(app)
File "/usr/local/lib/python3.10/site-packages/uvicorn/main.py", line 463, in run
server.run()
File "/usr/local/lib/python3.10/site-packages/uvicorn/server.py", line 60, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/local/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 633, in run_until_complete
self.run_forever()
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 600, in run_forever
self._run_once()
File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1896, in _run_once
handle._run()
File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "/usr/local/lib/python3.10/site-packages/uvicorn/server.py", line 77, in serve
await self.startup(sockets=sockets)
File "/usr/local/lib/python3.10/site-packages/uvicorn/server.py", line 158, in startup
sys.exit(1)
SystemExit: 1

"SSHException('No existing session')" errors with python ncclient

I am working on the code below, and I got SSHException('No existing session') error
from ncclient import manager
with manager.connect(host="192.168.1.40", port=830, username="cisco", password="cisco", hostkey_verify=False, device_params={'name':'iosxr'}, ssh_config=True, allow_agent=False,look_for_keys=False, timeout=10) as nc_conn:
nc_config = nc_conn.get_config(source='running').data_xml
print (nc_config)
yapi#MacBook-Pro-3 iTel % python test01.py
Traceback (most recent call last):
File "/Users/yapi/Documents/Scripts/Non-GIT/Python/2023/iTel/test01.py", line 4, in
with manager.connect(host="192.168.1.40", port=830, username="abdul", password="cisco", hostkey_verify=False, device_params={'name':'iosxr'}, ssh_config=True, allow_agent=False,look_for_keys=False, timeout=10) as nc_conn:
File "/usr/local/lib/python3.9/site-packages/ncclient/manager.py", line 176, in connect
return connect_ssh(*args, **kwds)
File "/usr/local/lib/python3.9/site-packages/ncclient/manager.py", line 143, in connect_ssh
session.connect(*args, **kwds)
File "/usr/local/lib/python3.9/site-packages/ncclient/transport/ssh.py", line 364, in connect
self._auth(username, password, key_filenames, allow_agent, look_for_keys)
File "/usr/local/lib/python3.9/site-packages/ncclient/transport/ssh.py", line 480, in _auth
raise AuthenticationError(repr(saved_exception))
ncclient.transport.errors.AuthenticationError: SSHException('No existing session')
yapi#MacBook-Pro-3 iTel %
I have tried using different flags in connect function, but no luck

FastAPI internal server error Exception in ASGI application

I developed an API with FastAPI and when I run it in my conda Ubuntu enviroment, and try any function all runs perfectly. But, when I run it in my conda Windows enviroment the API runs okey but when I try the functoin, I get the internal server error message as output and in the terminal i can see the following error described below. Note, the code is the same in both enviroments
Also, the conexion in jupyter notebook(in the conda windows enviroment) to the node works fine as well as any function I run.
This is the conexion via jupyter, thath works fine in both enviroments:
rpc_user = os.getenv("u1")
rpc_password = os.getenv("key2")
rpc_host = os.getenv("host")
rpc_client = AuthServiceProxy(f"http://{rpc_user}:{rpc_password}#{rpc_host}", timeout=120)
block_count = rpc_client.getblockcount()
print("---------------------------------------------------------------")
print("Block Count:", block_count)
print("---------------------------------------------------------------\n")
output:
---------------------------------------------------------------
Block Count: 773863
---------------------------------------------------------------
This is the code for the connection in the API that it is in a directory named blockchain_data :
import os
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import json
client = os.getenv("u1")
key = os.getenv("key2")
host= os.getenv("host")
rpc_client = AuthServiceProxy(f"http://{client}:{key}#{host}", timeout=120)
This is the router for getblockcount, that works fine in my ubuntu enviroment but not in the windows.
from fastapi import APIRouter
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from blockchain_data.node import rpc_client
router = APIRouter()
#router.get("/get/block/count")
def get_block_count():
block_count = rpc_client.getblockcount()
return {"Last block":block_count}
And the main:
from fastapi import FastAPI
from routers import routers
app = FastAPI()
app.include_router(routers.router)
#app.get("/")
def inicio():
return{
"message": "welcome"
}
ERROR:
←[1mGET /get/block/count HTTP/1.1←[0m" ←[91m500 Internal Server Error←[0m
←[31mERROR←[0m: Exception in ASGI application
Traceback (most recent call last):
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 407, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
return await self.app(scope, receive, send)
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\fastapi\applications.py", line 270, in __call__
await super().__call__(scope, receive, send)
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\starlette\applications.py", line 124, in __call__
await self.middleware_stack(scope, receive, send)
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\starlette\middleware\errors.py", line 184, in __call__
raise exc
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__
raise exc
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
await self.app(scope, receive, sender)
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in __call__
raise e
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\starlette\routing.py", line 706, in __call__
await route.handle(scope, receive, send)
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\starlette\routing.py", line 276, in handle
await self.app(scope, receive, send)
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\starlette\routing.py", line 66, in app
response = await func(request)
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\fastapi\routing.py", line 237, in app
raw_response = await run_endpoint_function(
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\fastapi\routing.py", line 165, in run_endpoint_function
return await run_in_threadpool(dependant.call, **values)
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\starlette\concurrency.py", line 41, in run_in_threadpool
return await anyio.to_thread.run_sync(func, *args)
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
result = context.run(func, *args)
File ".\routers\routers.py", line 17, in get_block_count
block_count = rpc_client.getblockcount()
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\bitcoinrpc\authproxy.py", line 139, in __call__
response = self._get_response()
File "C:\Users\grupo\miniconda3\envs\entorno1\lib\site-packages\bitcoinrpc\authproxy.py", line 186, in _get_response
raise JSONRPCException({
bitcoinrpc.authproxy.JSONRPCException: -342: non-JSON HTTP response with '401 Unauthorized' from server
I tried to run the conexion with the node in jupter and works fine, it something related to FastAPI or uvicorn

Is pyautogui work in the ubuntu 18.04 server version with no display accessed via ssh?

When I am import pyautogui it gives me:
Traceback (most recent call last):
File "app.py", line 2, in <module>
from register import reg
File "/home/nlp/Projects/face_recognition/register.py", line 12, in <module>
import pyautogui
File "/home/nlp/miniconda3/envs/face_recognition_env/lib/python3.6/site-packages/pyautogui/__init__.py", line 241, in <module>
import mouseinfo
File "/home/nlp/miniconda3/envs/face_recognition_env/lib/python3.6/site-packages/mouseinfo/__init__.py", line 223, in <module>
_display = Display(os.environ['DISPLAY'])
File "/home/nlp/miniconda3/envs/face_recognition_env/lib/python3.6/site-packages/Xlib/display.py", line 80, in __init__
self.display = _BaseDisplay(display)
File "/home/nlp/miniconda3/envs/face_recognition_env/lib/python3.6/site-packages/Xlib/display.py", line 62, in __init__
display.Display.__init__(*(self, ) + args, **keys)
File "/home/nlp/miniconda3/envs/face_recognition_env/lib/python3.6/site-packages/Xlib/protocol/display.py", line 58, in __init__
self.socket = connect.get_socket(name, host, displayno)
File "/home/nlp/miniconda3/envs/face_recognition_env/lib/python3.6/site-packages/Xlib/support/connect.py", line 76, in get_socket
return mod.get_socket(dname, host, dno)
File "/home/nlp/miniconda3/envs/face_recognition_env/lib/python3.6/site-packages/Xlib/support/unix_connect.py", line 78, in get_socket
raise error.DisplayConnectionError(dname, str(val))
Xlib.error.DisplayConnectionError: Can't connect to display ":0": [Errno 2] No such file or directory
I have tried this:
import os
os.environ['DISPLAY'] = ':0'
But still same error. According to one comment of to this link (https://github.com/asweigart/pyautogui/issues/161) in github says it is not accessible remotely. I have tried sudo xhost + command but it gives me below error.
xhost: unable to open display ""

installing woocommerce connector in odoo

i want to connect woocommerce and odoo. i have problem with woocommmerce connector installation in Odoo. i got the woocommerce connector from https://github.com/OCA/connector-woocommerce . i have upload this module into addons folder in odoo.. When i tried to update the module list in odoo, i got this error:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 537, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception).
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 574, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 310, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 307, in checked_call
return self.endpoint(*a, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 803, in __call__
return self.method(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 403, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 948, in call_button
action = self._call_kw(model, method, args, {})
File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 936, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 393, in old_api
result = new_api(recs, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 397, in new_api
result = [method(rec, *args, **kwargs) for rec in self]
File "/usr/lib/python2.7/dist-packages/openerp/addons/base/module/wizard/base_module_update.py", line 15, in update_module
self.updated, self.added = self.env['ir.module.module'].update_list()
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 462, in new_api
result = method(self._model, cr, uid, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/addons/base/module/module.py", line 654, in update_list
handler.load_addons()
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1308, in load_addons
m = __import__('openerp.addons.' + module)
File "/usr/lib/python2.7/dist-packages/openerp/modules/module.py", line 80, in load_module
mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
File "/usr/lib/python2.7/dist-packages/openerp/addons/connector_woocommerce/__init__.py", line 22, in <module>
from . import model
File "/usr/lib/python2.7/dist-packages/openerp/addons/connector_woocommerce/model/__init__.py", line 22, in <module>
from . import backend
File "/usr/lib/python2.7/dist-packages/openerp/addons/connector_woocommerce/model/backend.py", line 23, in <module>
from woocommerce import API
ImportError: No module named woocommerce
It seems like you do not have installed woocommerce REST api on your system.
install woocommerce using your terminal. here is the command
sudo pip install woocommerce
EDIT:
Open python prompt in terminal
$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from woocommerce import API
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named woocommerce
If it says No module named woocommerce means you have some installation issue with woocommerce.
I was facing same problem while installing woocommerce connector in odoo. After that i have installed woocommerce module by
pip install woocommerce. I was working on windows platform.
I was getting same problem after successfully installing woocommerce python module.
Here Problem is odoo is not finding woocommerce in it's addon folder.
So solution is here :
open folder "C:\Python27\Lib\site-packages".
This is the path where python modules are installed. From this folder find the folder 'woocommerce'.
copy this folder and put this in odoo server path which is
"D:\Odoo 8.0-20160107\server" .
Now restart odoo
Hope this will help you.

Resources