Comments (4)
@menew, have you seen the show_hids.py example? (https://github.com/rene-aguirre/pywinusb/blob/master/examples/show_hids.py), is this what you need.
Is the issue that you are reporting the fact that __repr__
does not return an unicode object?
Otherwise I don't think managing encodings in __repr__
(as os forcing ascii) is a good idea.
from pywinusb.
@rene-aguirre, thank you for reply!
have you seen the show_hids.py example? (https://github.com/rene-aguirre/pywinusb/blob/master/examples/show_hids.py), is this what you need.
Yes, but passing show_hids()
any encoders as output does not affect the situation.
For example, when I execute the following code:
# coding: utf-8
import sys
import codecs
import pywinusb.hid as hid
output = codecs.getwriter('mbcs')(sys.stdout)
hid.core.show_hids(output = output)
I got same UnicodeEncodeError as below, regardless of writer encoding:
Found HID class devices!, writting details...
Traceback (most recent call last):
File "C:\Users\menew\Desktop\Documents\show_hids.py", line 8, in <module>
hid.core.show_hids(output = output)
File "build\bdist.win-amd64\egg\pywinusb\hid\core.py", line 1596, in show_hids
device_name = str(dev)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 115-129: ordinal not in range(128)
And, if I edited hid.core.HidDevice.__repr__
as this, then show_hids()
shows report successfully without specifying output writer.
def __repr__(self):
# patched for python 2.x
# (`"%s" % self.product_name` raises UnicodeEncodeError if `product_name` has non-ascii characters)
return (u"HID device (vID=0x%04x, pID=0x%04x, v=0x%04x); %s; %s, " \
u"Path: %s" % (self.vendor_id, self.product_id, self.version_number,\
self.vendor_name, self.product_name, self.device_path)).encode('ascii', 'replace')
I think underlying problem is incompatibility that Python 2 demands __repr__
to return non-unicode object whereas Python 3 demands unicode object. Because of the incompatibility, some version detection code or forcing ascii charset seem necessary to make __repr__()
support both Python versions...
from pywinusb.
"...without specifying output writer"
I think the library has to be encoding transparent. The decoding has to be managed by the application, not the library.
My question, about the "show_hids.py" example is that it actually fails with your device, "as is".
Just run it and let me know if this raises the Unicode error.
Also, when you refer to the japanese locale, is this the system locale (how did you set it?) or the USB device string encoding?
I'd like to reproduce your issue to look for alternatives, would be possible to get a dump of the device that includes string descriptors?
from pywinusb.
@menew do you have a branch with your changes so issue #36 can be tested?
from pywinusb.
Related Issues (20)
- hid.core.show_hids() fails under Python 2 if there is a Unicode character in the device name HOT 1
- Freeze when closing handle from __del__ during python exit HOT 12
- Fail to run simple_feature.py example
- filtering devices by serial number HOT 1
- cx_Freeze can't find module pywinusb HOT 2
- Not reading mouse usb HOT 1
- get_usages() with usage ranges returns one less than what is in descriptor's range
- Running show_hids.py - A USB HID not showing in the list HOT 10
- Question about get input and send output from my custom USB device. HOT 5
- pywinusb vs pyusb HOT 2
- Options to get input reports
- InputReportProcessingThread is never closed
- Can't see all the HID devices connected to the PC HOT 1
- How do I send a simple feature report? HOT 2
- Set Feature Report data last byte corrupted HOT 4
- WinError 2 HOT 1
- Can I use this library to emulate HID mouse drivers without additional hardware? HOT 1
- PNP for tkinter HOT 4
- USB device isn't found
- HID RFID Tag Reading Issue HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pywinusb.