Search code examples
pythonpython-2.7pyscard

"EstablishContextException" error in Python


I've downloaded Python-2.7 and pyscard-1.7.0.win32-py2.7 and installed them on my computer to use my ACR122U smart card reader in my Windows-7.

After that I wrote the below program :

import sys
import time
sys.path.append("C:\\Python27\\Lib\\site-packages")

from smartcard.scard import *
import smartcard.util
from smartcard.System import readers

class Metro:

    isConnected = False
    isLoaded = False
    isAuthenticated = False
 .
 . # Methods censored.
 .

When I want to run the program, I receive these errors:

Python 2.7 (r27:82525, Jul  4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
>>> Connecting to the reader: 

Traceback (most recent call last):
  File "C:\Users\AmirEbrahim\Desktop\metro.py", line 195, in <module>
    m.connect()
  File "C:\Users\AmirEbrahim\Desktop\metro.py", line 63, in connect
    r = readers()
  File "C:\Python27\lib\site-packages\smartcard\System.py", line 41, in readers
    return smartcard.reader.ReaderFactory.ReaderFactory.readers(groups)
  File "C:\Python27\lib\site-packages\smartcard\reader\ReaderFactory.py", line 58, in readers
    zreaders += fm(groups)
  File "C:\Python27\lib\site-packages\smartcard\pcsc\PCSCReader.py", line 107, in readers
    hcontext = PCSCContext().getContext()
  File "C:\Python27\lib\site-packages\smartcard\pcsc\PCSCContext.py", line 53, in __init__
    PCSCContext.instance = PCSCContext.__PCSCContextSingleton()
  File "C:\Python27\lib\site-packages\smartcard\pcsc\PCSCContext.py", line 40, in __init__
    raise EstablishContextException(hresult)
EstablishContextException: <unprintable EstablishContextException object>
>>>

What's wrong?


Solution

  • I downloaded and installed an older version of PyScard from here and now it works fine. enter image description here