Troubleshooting
Common Issues
SystemDependencyError: Missing required system dependencies
Problem: When initializing ThaiIDCardReader, you get an error about missing system dependencies.
Solution: Install the required system packages:
Workaround: If dependencies are installed via other means:
NoReaderFoundError: No smart card reader found
Problem: The library cannot detect any smartcard readers.
Symptoms:
Solutions:
-
Check reader is connected:
-
Verify PC/SC daemon is running:
If not running:
- Test reader detection:
You should see your reader listed. Press Ctrl+C to exit.
- Check permissions: Then log out and log back in.
NoCardDetectedError: No card detected
Problem: Reader is detected but no card is found.
Symptoms:
Solutions:
- Ensure card is properly inserted:
- Card should be fully inserted
- Gold chip should be facing up and inserted first
-
Try removing and reinserting the card
-
Verify card is detected:
When you insert a card, you should see ATR information displayed. -
Check for card damage:
- Clean the chip with a soft cloth
- Try a different card if available
- Test the card in another reader
InvalidCardError: Not a valid Thai ID card
Problem: A card is detected but it's not recognized as a Thai ID card.
Symptoms:
Solutions:
- Verify it's a Thai ID card:
- Should be a Thai National ID card issued by the Thai government
-
Older cards may not work (try a newer card)
-
Check card type:
- Some cards may require different applet selection
- Contact card issuer if the card should work but doesn't
CardConnectionError: Failed to connect
Problem: Cannot establish connection to the card.
Possible causes:
-
Card in use by another process:
-
Reader malfunction:
- Disconnect and reconnect the reader
- Try a different USB port
-
Test with a different reader
-
Driver issues:
- Install proprietary drivers if needed
- Check reader manufacturer website
ImportError: No module named 'smartcard'
Problem: pyscard is not installed or failed to install.
Symptoms:
Solutions:
-
Install system dependencies first:
-
Reinstall pyscard:
-
If using uv:
"No such file or directory: winscard.h"
Problem: Compilation error when installing pyscard.
Solution: Install libpcsclite-dev:
Then reinstall:
Permission denied when accessing reader
Problem: User doesn't have permission to access the smartcard reader.
Symptoms:
Solutions:
-
Add user to scard group:
Then log out and log back in. -
Check udev rules:
-
Run with sudo (temporary):
⚠️ Not recommended for production!
Photo reading fails or is corrupted
Problem: Photo data is incomplete or invalid.
Solutions:
-
Retry reading:
-
Clean card chip:
- Use a soft, dry cloth
-
Avoid using liquids
-
Check card condition:
- Damaged cards may have corrupted photo data
-
Try a different card
-
Verify photo data:
Slow performance
Problem: Reading cards takes too long.
Solutions:
-
Skip photo reading if not needed:
This reduces read time from ~3s to <1s. -
Use specific reader index:
Avoids auto-detection overhead. -
Reuse reader instance:
-
Check USB connection:
- Use USB 2.0/3.0 ports (not USB hubs)
- Avoid using extension cables
TypeError: 'NoneType' object is not iterable
Problem: Trying to iterate over None value.
Common cause: Forgetting to check if photo exists:
# Wrong
photo_path = card.save_photo()
# Correct
if card.photo:
photo_path = card.save_photo()
else:
print("No photo data")
Encoding issues with Thai text
Problem: Thai characters display as garbage or question marks.
Solutions:
-
Ensure UTF-8 encoding:
-
Check terminal encoding:
-
Use proper font:
- Ensure your terminal/editor supports Thai characters
- Install Thai fonts if needed
CID validation fails
Problem: CID appears valid but fails validation.
Debugging:
from pythaiidcard import validate_cid, format_cid
cid = "1234567890123"
print(f"CID: {format_cid(cid)}")
print(f"Valid: {validate_cid(cid)}")
# Manual checksum calculation
digits = [int(d) for d in cid[:12]]
check_digit = int(cid[12])
checksum = sum((13-i) * d for i, d in enumerate(digits, 1)) % 11
expected = (11 - checksum) % 10
print(f"Expected: {expected}, Got: {check_digit}")
Getting Help
If you're still experiencing issues:
-
Check the logs:
-
Enable verbose mode (CLI):
-
Use the debug interface:
See real-time logs and connection status. -
Search existing issues:
-
Create a new issue:
- Include Python version, OS, reader model
- Provide error messages and logs
- Describe steps to reproduce
Platform-Specific Notes
Ubuntu 22.04+
Works out of the box with standard installation.
Ubuntu 20.04
May need to update pcscd:
Raspberry Pi
- Install dependencies as usual
- May need to add user to dialout group:
WSL2 (Windows Subsystem for Linux)
USB passthrough required: 1. Install usbipd-win 2. Attach USB reader to WSL:
# In PowerShell (as Administrator)
usbipd list
usbipd bind --busid <BUSID>
usbipd attach --wsl --busid <BUSID>
Docker
USB device access required:
# Add to Dockerfile
RUN apt-get update && apt-get install -y \
pcscd libpcsclite-dev python3-dev swig
# Run with device access
docker run --device=/dev/bus/usb:/dev/bus/usb --privileged ...
Compatibility
Tested Readers
- Generic USB CCID readers
- Gemalto readers
- ACS ACR122U
Known Issues
- Some older card readers may have compatibility issues
- Non-CCID readers may require additional drivers
Card Compatibility
- Thai National ID cards issued after 2010 work well
- Older cards (pre-2010) may have issues
- New cards with updated chip work best