Use python to get hid report descriptor - python

I want to use hidapi to get hid report descriptor, but I can't find the right way
import hid
device = hid.device()
device.open(0x1234, 0x5678)
descriptor = device.get_feature_report(0,0)
device.close()
Encountered the following error
How can I modify?
Traceback (most recent call last):
File ~\.spyder-py3\temp.py:18 in <module>
descriptor = device.get_feature_report(0,0)
File hid.pyx:358 in hid.device.get_feature_report
OSError: read error

Related

Attribute error that I am getting in an AI simple program that is not taking voice inputs

First few steps working , but error is coming that
Terminal Output (vs, pycharm, all of them , say same)
Traceback (most recent call last):
File "C:#################\ai.py", line 39, in takeCommand
audio = r.listen(source)
File "C:#################\Python\Python310\lib\site-packages\speech_recognition_init_.py", line 651, in listen
assert source.stream is not None, "Audio source must be entered before listening, see documentation for AudioSource; are you using source outside of a with statement?"
AssertionError: Audio source must be entered before listening, see documentation for AudioSource; are you using source outside of a with statement?
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:####################\ai.py", line 64, in <module>
query = takeCommand().lower()
File "C:#####3###############\ai.py", line 36, in takeCommand
with sr.Microphone() as source:
File "C:###############\Python\Python310\lib\site-packages\speech_recognition_init_.py", line 201, in exit
self.stream.close()
AttributeError: 'NoneType' object has no attribute 'close'
Process finished with exit code 1
I have never encountered this with my laptop. It's happening on friend's laptop. And nothing , absolutely nothing is fixing it, Now what?
i was expecting it to listen , but speech recognitions is not working!

How to fix the error 'TypeError: can't pickle time objects'?

I am using the OpenOPC library to read data from an OPC Server, I am using 'Matrikon OPC Simulation Server', when I try to read the data it sends me the following error:
TypeError: can't pickle time objects
The code I use is the following, I run it from the python console.
CODE:
import OpenOPC
opc = OpenOPC.client()
opc.connect('Matrikon.OPC.Simulation')
opc.read('Random.Int4')
When I run the line opc.read ('Random.Int4'), that's when the error appears.
This is how the variable appears in my MatrikonOPC Explorer:
This is the complete error:
Traceback (most recent call last):
File "C:\Python27\Lib\multiprocessing\queues.py", line 264, in _feed
send(obj)
TypeError: can't pickle time objects
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\User\PycharmProjects\OPC2\venv\lib\site-packages\OpenOPC.py", line 625, in read
return list(results)
File "C:\Users\User\PycharmProjects\OPC2\venv\lib\site-packages\OpenOPC.py", line 543, in iread
raise TimeoutError('Callback: Timeout waiting for data')
TimeoutError: Callback: Timeout waiting for data
I solved this issue by adding sync=True when calling opc.read()
CODE:
import OpenOPC
opc = OpenOPC.client()
opc.connect('Matrikon.OPC.Simulation')
opc.read('Random.Int4', sync=True)
Reference: mkwiatkowski/openopc

Why does python shelf module give an error at start up when opening file

I have been using the python shelf module to store face encodings from the python face-recognition module below. I did this to make the live image recognition process faster.
I then imported these encodings in another script using the shelf module again, assigned them to a variable, and use them further down my script. This all works fine in the python idle environment and when I run it from the terminal. However, on startup, the shelf module fails to import the data. Can anyone tell me why this happens at start-up? The error I get on the log file is below. I have been stuck on it for a few days now. Is there a better way of storing and reusing the encodings? Thanks in advance.
the bit of code that fails on start-up but runs fine otherwise
import shelve
shelfFile = shelve.open('face_encodings')
known_encodings = shelfFile['known_encodings']
known_names = shelfFile['known_names']
shelfFile.close()
the error on startup
Traceback (most recent call last): File "/usr/lib/python3.7/shelve.py", line 111, in __getitem__
value = self.cache[key]
KeyError: 'known_encodings'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Desktop/run/testing.py", line 4, in <module>
known_encodings = shelfFile['known_encodings']
File "/usr/lib/python3.7/shelve.py", line 113, in __getitem__
f = BytesIO(self.dict[key.encode(self.keyencoding)])
KeyError: b'known_encodings'
face-recognition module
https://pypi.org/project/face-recognition/

How to get namespace details for ecs

I want to print namespaces for my ecs-client. When I am using print(client.user_info.whoami()) I am getting the output. But when I am executing the below code I am getting attribute error.
from ecsclient.client import Client
from ecsclient.common.multitenancy import namespace
client = Client('3',
username='root',
password='password',
token_endpoint='https://abc.xyz.com:4443/login',
ecs_endpoint='https://abc.xyz.com:4443')
print(client.namespace.get_namespaces())
Error:
Traceback (most recent call last):
File "test.py", line 12, in <module>
print(client.namespace.get_namespaces())
AttributeError: 'Namespace' object has no attribute 'get_namespaces'
instead of using print(client.namespace.get_namespaces()) I used print(client.namespace.list()) and got the list of namespaces

Not able to open and load pickle file in python 3.6.1

I am trying to open and load pickle file but by two ways. But every time I am getting an error.
Request you to please help.
First way :
enron_data = pickle.load(open("D:/New/ud120-projects/final_project/final_project_dataset.pkl", "r"))
Error: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: a bytes-like object is required, not 'str'
Second Way :
enron_data = pickle.load(open("D:/New/ud120-projects/final_project/final_project_dataset.pkl", "rb"))
Error : Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_pickle.UnpicklingError: the STRING opcode argument must be quoted
Request you to please help
If you are on Windows you have to use a raw string and backslashes like this:
r'D:\path\to\your\file'

Categories