Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception ListReadersException raised after disconnecting PCSC reader #13

Closed
mayito opened this issue Sep 9, 2015 · 5 comments
Closed

Comments

@mayito
Copy link

mayito commented Sep 9, 2015

Hi,

I've noticed pyscard is not able to maintain the list of readers when a reader is connected / disconnected to / from my computer which runs on Windows 8.1 (64 bits).

I've written the following piece of code from the documentation to see if connections and disconnections of the reader are well detected :

from sys import stdin, exc_info
from time import sleep
from smartcard.ReaderMonitoring import ReaderMonitor, ReaderObserver

class printobserver( ReaderObserver ):
    def update( self, observable, (addedreaders, removedreaders) ):
        print "Added readers", addedreaders
        print "Removed readers", removedreaders

if __name__ == "__main__":
    try:
        print "Add or remove a smartcard reader to the system."
        print "This program will exit in 60 seconds"
        print ""
        readermonitor = ReaderMonitor()
        readerobserver = printobserver()
        readermonitor.addObserver( readerobserver )

        sleep(60)
    except error:
        print exc_info()[0], ': ', exc_info()[1]
    finally : 
        readermonitor.deleteObserver(readerobserver)

If the reader is connected before launching the program, it is well detected. But if it is connected / deconnected during the observer loop a ListReadersException is raised.

To avoid the problem, is there a way to force the reload of the entire pyscard module on demand ?

Cheers,

Thierry.

@LudovicRousseau
Copy link
Owner

Your sample code works fine for me on Mac OS X Yosemite.

I do not use Windows myself. If you can propose a patch for Windows that would help a lot.

@Koudy
Copy link

Koudy commented Apr 1, 2016

@mayito, hello. Did you find a solution?

@LudovicRousseau
Copy link
Owner

Maybe the change in #22 could help.

@LudovicRousseau
Copy link
Owner

I guess that #22 fixed the problem for you since I got no feedback.
Closing.

@leileigong
Copy link

I use pyscard-1.9.17, but i got this problem too.
I guess that #22 do not fixed the problem.

Traceback (most recent call last):
File "C:\Users\lei.virtualenvs\TestTool-gkAj8wo0\lib\site-packages\smartcard\CardMonitoring.py", line 162, in run
currentcards = self.cardrequest.waitforcardevent()
File "C:\Users\lei.virtualenvs\TestTool-gkAj8wo0\lib\site-packages\smartcard\CardRequest.py", line 73, in waitforcardevent
return self.pcsccardrequest.waitforcardevent()
File "C:\Users\lei.virtualenvs\TestTool-gkAj8wo0\lib\site-packages\smartcard\pcsc\PCSCCardRequest.py", line 288, in waitforcardevent
readernames = self.getReaderNames()
File "C:\Users\lei.virtualenvs\TestTool-gkAj8wo0\lib\site-packages\smartcard\pcsc\PCSCCardRequest.py", line 90, in getReaderNames
raise ListReadersException(hresult)
ListReadersException: ('Failed to list readers', -2146435042L)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants