LudovicRousseau / pyscard

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

Patch for Windows #216

Closed LudovicRousseau closed 1 month ago

LudovicRousseau commented 1 month ago
diff --git a/src/smartcard/pcsc/PCSCCardRequest.py b/src/smartcard/pcsc/PCSCCardRequest.py
index 74e9831..71e3e24 100644
--- a/src/smartcard/pcsc/PCSCCardRequest.py
+++ b/src/smartcard/pcsc/PCSCCardRequest.py
@@ -253,6 +253,10 @@ class PCSCCardRequest(AbstractCardRequest):
             elif SCARD_E_UNKNOWN_READER == hresult:
                 pass

+            # this happens on Windows when the last reader is disconnected
+            elif hresult in (SCARD_E_SYSTEM_CANCELLED, SCARD_E_NO_SERVICE):
+                pass
+
             # some error happened
             elif SCARD_S_SUCCESS != hresult:
                 raise CardRequestException(
@@ -381,6 +385,10 @@ class PCSCCardRequest(AbstractCardRequest):
             elif SCARD_E_UNKNOWN_READER == hresult:
                 pass

+            # this happens on Windows when the last reader is disconnected
+            elif hresult in (SCARD_E_SYSTEM_CANCELLED, SCARD_E_NO_SERVICE):
+                pass
+
             # some error happened
             elif SCARD_S_SUCCESS != hresult:
                 raise CardRequestException(
LudovicRousseau commented 1 month ago

merged