Yubico / python-yubico

Python code to talk to YubiKeys
https://developers.yubico.com/python-yubico/
BSD 2-Clause "Simplified" License
229 stars 33 forks source link

Updated README example to Python 3 #42

Closed mdxs closed 4 years ago

mdxs commented 5 years ago

Updated code example to Python 3 (see https://pythonclock.org/) and removed pre-release PyUSB notes, as the pip/PyPi and the setup install methods will now fetch a recent release of PyUSB. Consider updating https://developers.yubico.com/python-yubico/ as well, as it essentially shows the README document.

gdestuynder commented 5 years ago

I'm not sure the current code works with python3 - this is python-yubico 1.3.2 - maybe this issue should be "update code to work with python3" ;-)

Traceback (most recent call last):
  File "./test.py", line 6, in <module>
    yubikey = yubico.find_yubikey(debug=False)
  File "/usr/lib/python3.7/site-packages/yubico/yubikey.py", line 61, in find_key
    return YubiKey4_USBHID(debug, skip, hid_device)
  File "/usr/lib/python3.7/site-packages/yubico/yubikey_4_usb_hid.py", line 98, in __init__
    data = yubico_util.tlv_parse(self._read_capabilities())
  File "/usr/lib/python3.7/site-packages/yubico/yubikey_4_usb_hid.py", line 107, in _read_capabilities
    r_len = ord(response[0])
TypeError: ord() expected string of length 1, but int found
Exception ignored in: <function YubiKeyHIDDevice.__del__ at 0x7f42d8bafd08>
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/yubico/yubikey_usb_hid.py", line 138, in __del__
    self._close()
  File "/usr/lib/python3.7/site-packages/yubico/yubikey_usb_hid.py", line 345, in _close
    self._usb_handle.releaseInterface()
  File "/usr/lib/python3.7/site-packages/usb/legacy.py", line 235, in releaseInterface
    util.release_interface(self.dev, self.__claimed_interface)
  File "/usr/lib/python3.7/site-packages/usb/util.py", line 217, in release_interface
    device._ctx.managed_release_interface(device, interface)
AttributeError: 'NoneType' object has no attribute '_ctx'
mdxs commented 5 years ago

Up to very recently, it indeed wasn't Python 3 compatible; but happily https://github.com/Yubico/python-yubico/releases/tag/python-yubico-1.3.3 solved that (with #38).

dainnilsson commented 4 years ago

Thanks! https://developers.yubico.com/python-yubico/ will automatically pick up the change to the README the next time it's rebuilt.