How to use VSPE Api to do some operations? - com-port

from win32com.client.dynamic import Dispatch
class vspe:
def __init__(self):
self.vs = Dispatch("VSPE.VSPEApi")
self.activationKey = '<activationKey>'
self.vs.vspe_activate(self.activationKey)
self.vs.vspe_getVersionInformation()
if name == 'main':
vs = vspe()
I created a device with VSPE api. But it's fail. I do not known why?
It seems that this line lead to this issue:self.vs = Dispatch("VSPE.VSPEApi")
I met below issue:
Traceback (most recent call last):
File "C:\python38\lib\site-packages\win32com\client\dynamic.py", line 86, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/zhoudo1x/OneDrive - Intel Corporation/Desktop/gitproject/SoundWaveUI/utils/111.py", line 37, in
v = vspe()
File "C:/Users/zhoudo1x/OneDrive - Intel Corporation/Desktop/gitproject/SoundWaveUI/utils/111.py", line 5, in init
self.vs = Dispatch("VSPE.VSPEApi")
File "C:\python38\lib\site-packages\win32com\client_init_.py", line 117, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch, userName, clsctx)
File "C:\python38\lib\site-packages\win32com\client\dynamic.py", line 106, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\python38\lib\site-packages\win32com\client\dynamic.py", line 88, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(
pywintypes.com_error: (-2147221164, 'Class not registered', None, None)

Related

Attribute error: comtypes has no module named ISpeech

Traceback (most recent call last):
File "C:\Users\ammar\AppData\Local\Programs\Python\Python310\lib\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Users\ammar\AppData\Local\Programs\Python\Python310\lib\weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "h:\My Drive\Semester 6\Artificial Intelligence\JARVIS\jarvis.py", line 7, in <module>
engine = pt.init()
File "C:\Users\ammar\AppData\Local\Programs\Python\Python310\lib\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Users\ammar\AppData\Local\Programs\Python\Python310\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\ammar\AppData\Local\Programs\Python\Python310\lib\site-packages\pyttsx3\driver.py", line 52, in __init__
self._driver = self._module.buildDriver(weakref.proxy(self))
File "C:\Users\ammar\AppData\Local\Programs\Python\Python310\lib\site-packages\pyttsx3\drivers\sapi5.py", line 30, in buildDriver
return SAPI5Driver(proxy)
File "C:\Users\ammar\AppData\Local\Programs\Python\Python310\lib\site-packages\pyttsx3\drivers\sapi5.py", line 35, in __init__
self._tts = comtypes.client.CreateObject('SAPI.SPVoice')
File "C:\Users\ammar\AppData\Local\Programs\Python\Python310\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
return _manage(obj, clsid, interface=interface)
File "C:\Users\ammar\AppData\Local\Programs\Python\Python310\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
obj = GetBestInterface(obj)
File "C:\Users\ammar\AppData\Local\Programs\Python\Python310\lib\site-packages\comtypes\client\__init__.py", line 112, in GetBestInterface
interface = getattr(mod, itf_name)
AttributeError: module 'comtypes.gen.SpeechLib' has no attribute 'ISpeechVoice'
I have also tried re-installing Python and upgrading comtypes but everytime I get the same error. The program was working fine before I installed opencv-python. I have tried uninstalling it too but it doesn't make any difference.

Pyttsx3 Voice KeyError: 'sapi5'

Getting unknown voice id error. I tried with ( Pyttsx3 2.6 and python 3.6 ), ( pyttsx3==2.9 & python 3.10)
Traceback (most recent call last):
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\__init__.py", line 44, in init
eng = _activeEngines[driverName]
File "E:\anaconda3\envs\dummy\lib\weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Dnyanesh/PycharmProjects/dummy/main.py", line 5, in <module>
engine = pyttsx3.init()
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\__init__.py", line 46, in init
eng = Engine(driverName, debug)
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\engine.py", line 52, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\driver.py", line 77, in __init__
self._driver = self._module.buildDriver(weakref.proxy(self))
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\drivers\sapi5.py", line 22, in buildDriver
return SAPI5Driver(proxy)
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\drivers\sapi5.py", line 41, in __init__
self.setProperty('voice', self.getProperty('voice'))
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\drivers\sapi5.py", line 82, in setProperty
token = self._tokenFromId(value)
File "E:\anaconda3\envs\dummy\lib\site-packages\pyttsx3\drivers\sapi5.py", line 66, in _tokenFromId
raise ValueError('unknown voice id %s', id_)
ValueError: ('unknown voice id %s', 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech_OneCore\\Voices\\Tokens\\MSTTS_V110_enUS_DavidM')

Python3 multiprocessing shared dictionary consume by all process

I'm beginner for multiprocessing,
i would like to use multiprocessing for parallel code running with streaming data.
To start good, I have coded below and got error.
Could you please tell me correct way to print on the screen.
Code:
import sys
from multiprocessing import Process, Manager
import time
def producer(dic, name):
for i in range(10000):
dic["A"] = i
time.sleep(2)
def consumer(dic, name):
for i in range(10000):
aval = dic.get("A")
#print(f" {name} - Val = {aval}")
sys.stdout.write(f" {name} - Val = {aval}")
sys.stdout.flush()
time.sleep(2.2)
if __name__ == '__main__':
manager = Manager()
dic = manager.dict()
Process(target=producer, args=(dic,"TT")).start()
time.sleep(1)
Process(target=consumer, args=(dic,"Con1")).start()
Process(target=consumer, args=(dic,"Con2")).start()
When I run the same in the windows console, I got below error, how can I print Consumer's print function in the console.Thanks
(base) PS D:\> python .\mulpro.py
Process Process-3:
Process Process-4:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\multiprocessing\managers.py", line 811, in
_callmethod
conn = self._tls.connection
AttributeError: 'ForkAwareLocal' object has no attribute 'connection'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\multiprocessing\process.py", line 297, in _
bootstrap
self.run()
File "C:\ProgramData\Anaconda3\lib\multiprocessing\process.py", line 99, in ru
n
self._target(*self._args, **self._kwargs)
File "D:\mulpro.py", line 19, in consumer
aval = dic.get("A")
File "<string>", line 2, in get
File "C:\ProgramData\Anaconda3\lib\multiprocessing\managers.py", line 815, in
_callmethod
self._connect()
File "C:\ProgramData\Anaconda3\lib\multiprocessing\managers.py", line 802, in
_connect
conn = self._Client(self._token.address, authkey=self._authkey)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\connection.py", line 490, i
n Client
c = PipeClient(address)
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\multiprocessing\connection.py", line 691, i
n PipeClient
_winapi.WaitNamedPipe(address, 1000)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\managers.py", line 811, in
_callmethod
conn = self._tls.connection
FileNotFoundError: [WinError 2] The system cannot find the file specified
AttributeError: 'ForkAwareLocal' object has no attribute 'connection'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\multiprocessing\process.py", line 297, in _
bootstrap
self.run()
File "C:\ProgramData\Anaconda3\lib\multiprocessing\process.py", line 99, in ru
n
self._target(*self._args, **self._kwargs)
File "D:\mulpro.py", line 19, in consumer
aval = dic.get("A")
File "<string>", line 2, in get
File "C:\ProgramData\Anaconda3\lib\multiprocessing\managers.py", line 815, in
_callmethod
self._connect()
File "C:\ProgramData\Anaconda3\lib\multiprocessing\managers.py", line 802, in
_connect
conn = self._Client(self._token.address, authkey=self._authkey)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\connection.py", line 490, i
n Client
c = PipeClient(address)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\connection.py", line 691, i
n PipeClient
_winapi.WaitNamedPipe(address, 1000)
FileNotFoundError: [WinError 2] The system cannot find the file specified
Process Process-2:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\multiprocessing\process.py", line 297, in _
bootstrap
self.run()
File "C:\ProgramData\Anaconda3\lib\multiprocessing\process.py", line 99, in ru
n
self._target(*self._args, **self._kwargs)
File "D:\mulpro.py", line 13, in producer
dic["A"] = i
File "<string>", line 2, in __setitem__
File "C:\ProgramData\Anaconda3\lib\multiprocessing\managers.py", line 818, in
_callmethod
conn.send((self._id, methodname, args, kwds))
File "C:\ProgramData\Anaconda3\lib\multiprocessing\connection.py", line 206, i
n send
self._send_bytes(_ForkingPickler.dumps(obj))
File "C:\ProgramData\Anaconda3\lib\multiprocessing\connection.py", line 280, i
n _send_bytes
ov, err = _winapi.WriteFile(self._handle, buf, overlapped=True)
BrokenPipeError: [WinError 232] The pipe is being closed
The reason might be that the main process doesn't wait for two children process, so make your code like this could work:
def run():
manager = Manager()
dic = manager.dict()
Process(target=producer, args=(dic,"TT")).start()
time.sleep(1)
Process(target=consumer, args=(dic,"Con1")).start()
Process(target=consumer, args=(dic,"Con2")).start()
while True:
pass
if __name__ == '__main__':
run()
However it's very strange that if I append a dead loop in main instead of using another function, it still raise that exception. Anyway, the code above could help.

Creating a AsyncHTTPClient object in a class causes FileNotFound Error

When I try to make the HTTP client a class variable of my tcp server class I see the following error:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "cisco-dial-out-mdt-async-client.py", line 208, in <module>
tcp_server.start(0)
File "/home/lab/venv3.7/lib/python3.7/site-packages/tornado/tcpserver.py", line 244, in start
self.add_sockets(sockets)
File "/home/lab/venv3.7/lib/python3.7/site-packages/tornado/tcpserver.py", line 166, in add_sockets
sock, self._handle_connection
File "/home/lab/venv3.7/lib/python3.7/site-packages/tornado/netutil.py", line 279, in add_accept_handler
io_loop.add_handler(sock, accept_handler, IOLoop.READ)
File "/home/lab/venv3.7/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 99, in add_handler
self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
File "/usr/lib/python3.7/asyncio/selector_events.py", line 324, in add_reader
return self._add_reader(fd, callback, *args)
File "/usr/lib/python3.7/asyncio/selector_events.py", line 254, in _add_reader
child 13 (pid 3260) killed by signal 2, restarting
(handle, None))
File "/usr/lib/python3.7/selectors.py", line 359, in register
Traceback (most recent call last):
File "cisco-dial-out-mdt-async-client.py", line 208, in <module>
self._selector.register(key.fd, poller_events)
Traceback (most recent call last):
FileExistsError: [Errno 17] File exists
File "/usr/lib/python3.7/asyncio/selector_events.py", line 251, in _add_reader
tcp_server.start(0)
File "/home/lab/venv3.7/lib/python3.7/site-packages/tornado/tcpserver.py", line 241, in start
process.fork_processes(num_processes, max_restarts)
File "/home/lab/venv3.7/lib/python3.7/site-packages/tornado/process.py", line 175, in fork_processes
key = self._selector.get_key(fd)
raise RuntimeError("Too many child restarts, giving up")
File "/usr/lib/python3.7/selectors.py", line 192, in get_key
RuntimeError: Too many child restarts, giving up
raise KeyError("{!r} is not registered".format(fileobj)) from None
KeyError: '9 is not registered'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "cisco-dial-out-mdt-async-client.py", line 208, in <module>
tcp_server.start(0)
Traceback (most recent call last):
File "/home/lab/venv3.7/lib/python3.7/site-packages/tornado/tcpserver.py", line 244, in start
File "/usr/lib/python3.7/asyncio/selector_events.py", line 251, in _add_reader
self.add_sockets(sockets)
File "/home/lab/venv3.7/lib/python3.7/site-packages/tornado/tcpserver.py", line 166, in add_sockets
key = self._selector.get_key(fd)
File "/usr/lib/python3.7/selectors.py", line 192, in get_key
sock, self._handle_connection
File "/home/lab/venv3.7/lib/python3.7/site-packages/tornado/netutil.py", line 279, in add_accept_handler
raise KeyError("{!r} is not registered".format(fileobj)) from None
KeyError: '9 is not registered'
When I remove the line that creates the object it works fine
class TelemetryTCPDialOutServer(TCPServer):
def __init__(self, elasticsearch_server):
super().__init__()
self.elastic_server = elasticsearch_server
self.lock = Lock()
log_name = __file__.strip('.py')
self.log = self.init_log(f"{log_name}.log")
self.lock = Lock()
self.http_client = AsyncHTTPClient() <== This line
Is it possible to put the http client in the class or make it a local object to some of the class functions. (This way works too).
Thansk
It looks like something has really messed up your stack trace, but I think the problem is that you're calling tcp_server.start(0) too late. start(0) forks multiple child processes, and it's invalid to fork multiple processes once the event loop has been created.
If you can, move this start(0) call earlier (typically it's the first thing you do after processing your command line or config file). If you can't move it earlier, you'll have to split up the process creation from starting the server. This is the "advanced multi-process" pattern from https://www.tornadoweb.org/en/stable/tcpserver.html:
# This part comes very early, just after processing configs
sockets = bind_sockets(8888)
tornado.process.fork_processes(0)
# This part can come later
server = TCPServer()
server.add_sockets(sockets)
IOLoop.current().start()

Having trouble with win32com in python

when i run the command
import win32com.client
exl = win32com.client.Dispatch('Excel.Application')
im getting the following error.. how can i solve this
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\Python36\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Program Files\Python36\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Program Files\Python36\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147024893, 'The system cannot find the path specified.', None, None)
check what your excel programID or shortcut is from your excel properties, it might be different. This only gives you access to read environment variables where your application ID is stored.

Resources