LudovicRousseau / pyscard

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

TypeError: CardRequestTimeoutException.__init__() got an unexpected keyword argument 'hresult' #165

Closed James-E-A closed 6 months ago

James-E-A commented 6 months ago

Your system information

Please describe your issue in as much detail as possible:

_Describe what you expected should happen._

I should have got a CardRequestTimeoutException when the card wasn't found.

Describe what *did* happen.

I got a TypeError exception when the card wasn't found.

Traceback (most recent call last):
  File "…\test007.py", line 15, in <module>
    crd = req.waitforcard()
  File "…\.venv\Lib\site-packages\smartcard\CardRequest.py", line 68, in waitforcard
    return self.pcsccardrequest.waitforcard()
  File "…\.venv\Lib\site-packages\smartcard\pcsc\PCSCCardRequest.py", line 216, in waitforcard
    raise CardRequestTimeoutException(hresult=hresult)
TypeError: CardRequestTimeoutException.__init__() got an unexpected keyword argument 'hresult'

Steps for reproducing this issue:

  1. Install pyscard
  2. Don't insert a smartcard
  3. Run this code:

    import smartcard  # https://pypi.org/project/pyscard/
    import smartcard.CardRequest
    import smartcard.CardType
    
    class MyCardType(smartcard.CardType.CardType):
       @classmethod
       def matches(cls, atr, reader=None):
           return bytes(atr).startswith(cls.prefix)
       prefix = b'\x3b\xff\x13\x00\x00'
    
    req = smartcard.CardRequest.CardRequest(cardType=MyCardType)
    crd = req.waitforcard()
    con = crd.connection
    con.connect()
    print('ATR:', bytes(con.getATR()).hex())
LudovicRousseau commented 6 months ago

Thanks