我试图在Windows 7 64位上使用python 2.6.6列出我的USB设备。这是我正在使用的脚本:
import usb
def list_devices(idVendor=None, idProduct=None):
"""Look through the usb tree for devices with a given Vendor ID and, if
specified, a Product ID. Return list of usb.Device classes.
"""
return_devices=[]
busses=usb.busses()
for bus in busses:
for device in bus.devices:
if device.idVendor == idVendor or idVendor==None:
if device.idProduct == idProduct or idProduct == None:
print("Vendor id: "+str(hex(device.idVendor))+" Product id: "+str(hex(device.idProduct))+"\n")
return_devices.append(device)
return return_devices
if __name__=="__main__":
list_devices()
这是我收到的错误消息:
Traceback (most recent call last):
File "C:/Python26/Scripts/find_usb_devices", line 25, in <module>
list_devices()
File "C:/Python26/Scripts/find_usb_devices", line 13, in list_devices
busses=usb.busses()
File "C:\Python26\lib\site-packages\usb\legacy.py", line 333, in busses
return (Bus(),)
File "C:\Python26\lib\site-packages\usb\legacy.py", line 329, in __init__
self.devices = [Device(d) for d in core.find(find_all=True)]
File "C:\Python26\lib\site-packages\usb\legacy.py", line 314, in __init__
self.configurations = [Configuration(c) for c in dev]
File "C:\Python26\lib\site-packages\usb\core.py", line 723, in __iter__
yield Configuration(self, i)
File "C:\Python26\lib\site-packages\usb\core.py", line 419, in __init__
configuration
File "C:\Python26\lib\site-packages\usb\backend\libusb10.py", line 471, in get_configuration_descriptor
config, byref(cfg)))
File "C:\Python26\lib\site-packages\usb\backend\libusb10.py", line 403, in _check
raise USBError(_str_error[ret], ret, _libusb_errno[ret])
USBError: [Errno 2] Entity not found
如果有人可以帮助解决此问题,那将会很方便。奇怪的是,当我在运行Windows 10的笔记本电脑上在Python 2.7上尝试相同的代码时,它运行顺畅。提前谢谢。