CardConnectionException on initial run #3

Open
opened 2026-06-12 11:46:25 +02:00 by kalipso · 2 comments
Owner

Setting up gatekeeper on a fresh instance throws a CardConnectionExpection. I assume this might happen because i have now usb card reader attached - still this should be handled gracefully.

Steps to reproduce:

git clone ...
cd gatekeeper
nix develop .
uv sync
uv run fastapi dev

The following error is logged during startup:

ERROR:app.services.scanner:Error in scan function: Service not available. (0x8010001D)
Traceback (most recent call last):
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 267, in _scan_loop
    card_content = self._read_card()
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 283, in _read_card
    cardservice = getCardService(3)
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 46, in getCardService
    cardrequest = CardRequest(timeout=timeout, cardType=cardtype)
  File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/CardRequest.py", line 66, in __init__
    self.pcsccardrequest = PCSCCardRequest(
                           ~~~~~~~~~~~~~~~^
        newcardonly, readers, cardType, cardServiceClass, timeout
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 107, in __init__
    raise CardConnectionException(hresult=hresult)
smartcard.Exceptions.CardConnectionException: Service not available. (0x8010001D)
ERROR:app.services.scanner:Error in scan function: Service not available. (0x8010001D)
Traceback (most recent call last):
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 267, in _scan_loop
    card_content = self._read_card()
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 283, in _read_card
    cardservice = getCardService(3)
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 46, in getCardService
    cardrequest = CardRequest(timeout=timeout, cardType=cardtype)
  File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/CardRequest.py", line 66, in __init__
    self.pcsccardrequest = PCSCCardRequest(
                           ~~~~~~~~~~~~~~~^
        newcardonly, readers, cardType, cardServiceClass, timeout
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 107, in __init__
    raise CardConnectionException(hresult=hresult)
smartcard.Exceptions.CardConnectionException: Service not available. (0x8010001D)
ERROR:app.services.scanner:Error in scan function: Service not available. (0x8010001D)
Traceback (most recent call last):
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 267, in _scan_loop
    card_content = self._read_card()
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 283, in _read_card
    cardservice = getCardService(3)
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 46, in getCardService
    cardrequest = CardRequest(timeout=timeout, cardType=cardtype)
  File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/CardRequest.py", line 66, in __init__
    self.pcsccardrequest = PCSCCardRequest(
                           ~~~~~~~~~~~~~~~^
        newcardonly, readers, cardType, cardServiceClass, timeout
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 107, in __init__
    raise CardConnectionException(hresult=hresult)
smartcard.Exceptions.CardConnectionException: Service not available. (0x8010001D)
ERROR:app.services.scanner:Error in scan function: Service not available. (0x8010001D)
Traceback (most recent call last):
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 267, in _scan_loop
    card_content = self._read_card()
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 283, in _read_card
    cardservice = getCardService(3)
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 46, in getCardService
    cardrequest = CardRequest(timeout=timeout, cardType=cardtype)
  File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/CardRequest.py", line 66, in __init__
    self.pcsccardrequest = PCSCCardRequest(
                           ~~~~~~~~~~~~~~~^
        newcardonly, readers, cardType, cardServiceClass, timeout
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 107, in __init__
    raise CardConnectionException(hresult=hresult)
smartcard.Exceptions.CardConnectionException: Service not available. (0x8010001D)
ERROR:app.services.scanner:Error in scan function: Service not available. (0x8010001D)
Traceback (most recent call last):
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 267, in _scan_loop
    card_content = self._read_card()
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 283, in _read_card
    cardservice = getCardService(3)
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 46, in getCardService
    cardrequest = CardRequest(timeout=timeout, cardType=cardtype)
  File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/CardRequest.py", line 66, in __init__
    self.pcsccardrequest = PCSCCardRequest(
                           ~~~~~~~~~~~~~~~^
        newcardonly, readers, cardType, cardServiceClass, timeout
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 107, in __init__
    raise CardConnectionException(hresult=hresult)
smartcard.Exceptions.CardConnectionException: Service not available. (0x8010001D)
ERROR:app.services.scanner:Error in scan function: Service not available. (0x8010001D)
Traceback (most recent call last):
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 267, in _scan_loop
    card_content = self._read_card()
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 283, in _read_card
    cardservice = getCardService(3)
  File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 46, in getCardService
    cardrequest = CardRequest(timeout=timeout, cardType=cardtype)
  File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/CardRequest.py", line 66, in __init__
    self.pcsccardrequest = PCSCCardRequest(
                           ~~~~~~~~~~~~~~~^
        newcardonly, readers, cardType, cardServiceClass, timeout
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 107, in __init__
    raise CardConnectionException(hresult=hresult)
smartcard.Exceptions.CardConnectionException: Service not available. (0x8010001D)

Before this is logged too:

CRITICAL:app.main:MIFARE APP MASTER KEY not found!
CRITICAL:app.main:Writing and reading cards is disabled!
Setting up gatekeeper on a fresh instance throws a CardConnectionExpection. I assume this might happen because i have now usb card reader attached - still this should be handled gracefully. Steps to reproduce: ```bash git clone ... cd gatekeeper nix develop . uv sync uv run fastapi dev ``` The following error is logged during startup: ``` ERROR:app.services.scanner:Error in scan function: Service not available. (0x8010001D) Traceback (most recent call last): File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 267, in _scan_loop card_content = self._read_card() File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 283, in _read_card cardservice = getCardService(3) File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 46, in getCardService cardrequest = CardRequest(timeout=timeout, cardType=cardtype) File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/CardRequest.py", line 66, in __init__ self.pcsccardrequest = PCSCCardRequest( ~~~~~~~~~~~~~~~^ newcardonly, readers, cardType, cardServiceClass, timeout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 107, in __init__ raise CardConnectionException(hresult=hresult) smartcard.Exceptions.CardConnectionException: Service not available. (0x8010001D) ERROR:app.services.scanner:Error in scan function: Service not available. (0x8010001D) Traceback (most recent call last): File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 267, in _scan_loop card_content = self._read_card() File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 283, in _read_card cardservice = getCardService(3) File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 46, in getCardService cardrequest = CardRequest(timeout=timeout, cardType=cardtype) File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/CardRequest.py", line 66, in __init__ self.pcsccardrequest = PCSCCardRequest( ~~~~~~~~~~~~~~~^ newcardonly, readers, cardType, cardServiceClass, timeout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 107, in __init__ raise CardConnectionException(hresult=hresult) smartcard.Exceptions.CardConnectionException: Service not available. (0x8010001D) ERROR:app.services.scanner:Error in scan function: Service not available. (0x8010001D) Traceback (most recent call last): File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 267, in _scan_loop card_content = self._read_card() File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 283, in _read_card cardservice = getCardService(3) File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 46, in getCardService cardrequest = CardRequest(timeout=timeout, cardType=cardtype) File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/CardRequest.py", line 66, in __init__ self.pcsccardrequest = PCSCCardRequest( ~~~~~~~~~~~~~~~^ newcardonly, readers, cardType, cardServiceClass, timeout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 107, in __init__ raise CardConnectionException(hresult=hresult) smartcard.Exceptions.CardConnectionException: Service not available. (0x8010001D) ERROR:app.services.scanner:Error in scan function: Service not available. (0x8010001D) Traceback (most recent call last): File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 267, in _scan_loop card_content = self._read_card() File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 283, in _read_card cardservice = getCardService(3) File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 46, in getCardService cardrequest = CardRequest(timeout=timeout, cardType=cardtype) File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/CardRequest.py", line 66, in __init__ self.pcsccardrequest = PCSCCardRequest( ~~~~~~~~~~~~~~~^ newcardonly, readers, cardType, cardServiceClass, timeout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 107, in __init__ raise CardConnectionException(hresult=hresult) smartcard.Exceptions.CardConnectionException: Service not available. (0x8010001D) ERROR:app.services.scanner:Error in scan function: Service not available. (0x8010001D) Traceback (most recent call last): File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 267, in _scan_loop card_content = self._read_card() File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 283, in _read_card cardservice = getCardService(3) File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 46, in getCardService cardrequest = CardRequest(timeout=timeout, cardType=cardtype) File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/CardRequest.py", line 66, in __init__ self.pcsccardrequest = PCSCCardRequest( ~~~~~~~~~~~~~~~^ newcardonly, readers, cardType, cardServiceClass, timeout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 107, in __init__ raise CardConnectionException(hresult=hresult) smartcard.Exceptions.CardConnectionException: Service not available. (0x8010001D) ERROR:app.services.scanner:Error in scan function: Service not available. (0x8010001D) Traceback (most recent call last): File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 267, in _scan_loop card_content = self._read_card() File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 283, in _read_card cardservice = getCardService(3) File "/home/kalipso/proggn/malobeo/gatekeeper/app/services/scanner.py", line 46, in getCardService cardrequest = CardRequest(timeout=timeout, cardType=cardtype) File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/CardRequest.py", line 66, in __init__ self.pcsccardrequest = PCSCCardRequest( ~~~~~~~~~~~~~~~^ newcardonly, readers, cardType, cardServiceClass, timeout ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/home/kalipso/proggn/malobeo/gatekeeper/.venv/lib/python3.13/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 107, in __init__ raise CardConnectionException(hresult=hresult) smartcard.Exceptions.CardConnectionException: Service not available. (0x8010001D) ``` Before this is logged too: ``` CRITICAL:app.main:MIFARE APP MASTER KEY not found! CRITICAL:app.main:Writing and reading cards is disabled! ```
ahtlon was assigned by kalipso 2026-06-12 11:46:57 +02:00
Author
Owner

The CRITICAL:app.main:MIFARE APP MASTER KEY not found! is gone after i did a cp .env.example .env

The `CRITICAL:app.main:MIFARE APP MASTER KEY not found!` is gone after i did a `cp .env.example .env`
Owner

Start the app with DISABLE_CARDS=1 uv run fastapi dev to disable the background scanner

Start the app with `DISABLE_CARDS=1 uv run fastapi dev` to disable the background scanner
Sign in to join this conversation.
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: malobeo/gatekeeper#3