LudovicRousseau / pyscard

pyscard smartcard library for python
http://pyscard.sourceforge.net/
GNU Lesser General Public License v2.1
383 stars 110 forks source link

Using the observer based approach randomly fails with CardRequestTimeoutException #64

Closed knedlsepp closed 5 years ago

knedlsepp commented 6 years ago

I've been using the sample_TransmitCardObserver.py example for reading mifare-tags. I do want to run this script as a daemon, but I'm getting random CardRequestTimeoutException: Time-out during card request errors. Those keep mostly popping up, when quickly interacting with the reader and the tag - putting it to the reader only for a short time and pulling it away. The full trace is as follows:

Traceback (most recent call last):
  File "lib/python3.6/site-packages/smartcard/CardMonitoring.py", line 160, in run
    currentcards = self.cardrequest.waitforcardevent()
  File "lib/python3.6/site-packages/smartcard/CardRequest.py", line 72, in waitforcardevent
    return self.pcsccardrequest.waitforcardevent()
  File "lib/python3.6/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 309, in waitforcardevent
    raise CardRequestTimeoutException()
smartcard.Exceptions.CardRequestTimeoutException: Time-out during card request

After this happens the program just hangs indefinitely. I tracked the issue down to: https://github.com/LudovicRousseau/pyscard/pull/22 Without this PR, the Monitor just keeps on going, printing the occasional stack-trace, but otherwise seeming to work fine. I'm now using pyscard exclusively with this patch locally undone. I would however love to see this fixed here. I guess for now I'd prefer for #22 to be un-merged. If the only downside of that is "duplicate error message printouts" not being prevented, I would prefer the monitoring-thread not being stopped on a CardRequestTimeoutException and mostly working flawlessly otherwise.

LudovicRousseau commented 6 years ago

What operating system are you using?

knedlsepp commented 6 years ago

I've had this issue on macOS using pyscard from nixpkgs.

LudovicRousseau commented 6 years ago

What version of macOS?

knedlsepp commented 6 years ago

I'm running 10.11.6.

knedlsepp commented 6 years ago

I'm also experiencing the same problem on a Raspberry pi 3B+ running NixOS-18.03 and using pcsclite and the CCID driver. The card reader is a ACR122U.

LudovicRousseau commented 6 years ago

Good to know the problem is not related to macOS but is also present on GNU/Linux + pcsclite. Do you also have the problem with contact cards? or only with contactless cards?

knedlsepp commented 6 years ago

Sadly the ACR122U is the only reader I own.

LudovicRousseau commented 5 years ago

I can reproduce the problem. Sorry for the delay. I am working on a fix.

knedlsepp commented 5 years ago

Great to hear!

LudovicRousseau commented 5 years ago

Fixed in https://github.com/LudovicRousseau/pyscard/commit/2bd0b0fd0d464483374663282602e02d54715e4f