Im working with MFRC522-Python library, I READ the RFid Uid then I open a webbrowser with a specific URL composed by the uid of each card.

The thing is in Raspbian Buster (RPI 3b+) cannot run Chrome-Browser as SUDO from a python script.

I would like to know if is there any way to read the RC522 without SUDO


import signal
import time
import sys
import os
import webbrowser
from pirc522 import RFID
#chrome = chromium-browser()

run = True
rdr = RFID()
util = rdr.util()
util.debug = True

def end_read(signal,frame):
    global run
    print("\nCtrl+C captured, ending read.")
    run = False

signal.signal(signal.SIGINT, end_read)

os.system('chromium-browser --app=http://localhost/ --kiosk --user-data-dir /home/pi & ')

while run:

    (error, data) = rdr.request()
    if not error:
        print("\nDetected: " + format(data, "02x"))

    (error, uid) = rdr.anticoll()
    if not error:
        print("Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3]))

        print("Setting tag")

    os.system('chromium-browser --app=http://localhost/verperfil/rfid.php?rfid='+str(uid[0])+''+str(uid[1])+''+str(uid[2])+''+str(uid[3])+'')
        #util.auth(rdr.auth_a, [0x12, 0x34, 0x56, 0x78, 0x96, 0x92])
        #util.auth(rdr.auth_b, [0x74, 0x00, 0x52, 0x35, 0x00, 0xFF])



pi@raspberrypi:~ $ python /var/www/html/pi-rc522/examples/asigna.py
Traceback (most recent call last):
  File "/var/www/html/pi-rc522/examples/asigna.py", line 11, in <module>
    rdr = RFID()
  File "build/bdist.linux-armv7l/egg/pirc522/rfid.py", line 78, in __init__
RuntimeError: No access to /dev/mem.  Try running as root!
pi@raspberrypi:~ $


sudo python /var/www/html/pi-rc522/examples/asigna.py
/usr/local/lib/python2.7/dist-packages/pi_rc522-2.2.1-py2.7.egg/pirc522/rfid.py:78: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
--user-data-dir --disable-quic --enable-tcp-fast-open --ppapi-flash-path=/usr/lib/chromium-browser/libpepflashplayer.so --ppapi-flash-args=enable_stagevideo_auto=0 --ppapi-flash-version=
No protocol specified
[4692:4692:0807/011632.383841:ERROR:browser_main_loop.cc(596)] Failed to put Xlib into threaded mode.
No protocol specified

(chromium-browser-v7:4692): Gtk-WARNING **: 01:16:32.388: cannot open display: :10.0
  • Please don't ask nearly the same question two times. Instead edit your first question. – Ingo Aug 7 at 10:42
  • Im so sorry, it will never going to happen again, thanks for take care and moderating this wonderfull place. – obdb Aug 7 at 13:47

As the output complains about "No access to /dev/mem", you could give access to the user running the script:

sudo chown pi /dev/mem

If your user is not pi, change the user name.

  • Hello, thanks for the answer and your time. this is my output after chown to pi (you are right, pi is the user) pi@raspberrypi:~ $ sudo chown pi /dev/mem pi@raspberrypi:~ $ python /var/www/html/pi-rc522/examples/asigna.py Traceback (most recent call last): File "/var/www/html/pi-rc522/examples/asigna.py", line 11, in <module> rdr = RFID() File "build/bdist.linux-armv7l/egg/pirc522/rfid.py", line 78, in __init__ RuntimeError: No access to /dev/mem. Try running as root! pi@raspberrypi:~ $ – obdb Aug 7 at 13:42
  • After the chown (if it has not been reverted) user pi should be able to access /dev/mem. It is possible that the program tries also something else here and the error message is not that specific. Or maybe what it wants to do really requires root, beyond the file permissions. You could try the suggestions from the other comment about starting the browser from a root process. – RalfFriedl Aug 8 at 16:46

Well, i was "closed-in-to-just-one-posibility" -or not thinking clear- The MFRC522-Python lib "Read.py" cannot be executed without sudo AND the chromium-browser CANNOT BE EXECUTED as SUDO, so... Afters a lot of Coffee and hours i found that i can execute the Read.py as SUDO and inside of it, the web browser directly with another username

basicly i have modified my script and replace this


to this:

os.system('sudo -upi chromium-browser http://localhost/verperfil/rfid.php?rfid='+str(uid[0])+''+str(uid[1])+''+str(uid[2])+''+str(uid[3])+'')

and the browser just starts perfectly, one thing, is i dont know why the script get paused when browser is opened.. but this topic is ended :) THANKS TO ALL OF US

Not the answer you're looking for? Browse other questions tagged or ask your own question.