1

I am working on a data acquisition project where I am sending a bunch of sensor data to the cloud. Here is a small snippet from my code:

#!/usr/bin/python3
# coding: utf-8

import ctypes
from systemd import journal
.
.
.#Rest of the code
.
journal.send(
        channel = 'sensor',
        priority = journal.Priority.INFO,
        messageid = "%d" % (seq_num),
        timestamp = "%s" % (CurrentTimestamp),
        tdiff = "%s" % (dt),     
        acc_x="%f" % (cax),
        acc_y="%f" % (cay),
        acc_z="%f" % (caz),
        gyr_x="%f" % (cgx),
        gyr_y="%f" % (cgy),
        gyr_z="%f" % (cgz),
        horn = "%d" % (GPIO.input(hornpin)),
        brake = "%d" % (GPIO.input(brakepin)),
        rpm = "%d" % (GPIO.input(rpmpin)),
        lux = "%f" % (lux),
        temperature_batterypack = "%d" % (temperature_batterypack),
        temperature_ambientair = "%d" % (temperature_ambientair),
        temperature_scooterbody = "%d" % (temperature_scooterbody),
        )

I have designed my own board using the public schematics of Raspberry Pi Compute module 3. The OS that I am using is the latest version of Raspbian Stretch Lite (June 2018 release). I am trying to autostart the code at boot by adding the following line in /etc/rc.local before exit 0:

sudo python3 /home/pi/test_scripts/cloud_test.py &

and I get the following error:

AttributeError: module 'systemd.journal' has no attribute 'Priority'

I even tried autostarting using systemd (so I created a service file) and when I check the status of the service file, it gives me the same exact error. Whereas, if I don't do auto start and manually run the code on the command prompt as:

$ python3 cloud_test.py

the code runs correctly and sends data to the cloud and I can see all the data on a website. This means all modules and python packages are correctly installed and I do not get any error. I also made by python script executable by using sudo chmod +x cloud_test.py and have also included #!/usr/bin/python3 at the top of my code. Then why do I see the error AttributeError: module 'systemd.journal' has no attribute 'Priority' only on autostart but not on manual start?

7
  • Have a look at you Pi forum topic: raspberrypi.org/forums/viewtopic.php?f=29&t=220304#p1352270
    – Dirk
    Aug 13, 2018 at 9:16
  • @Dirk: I think the OP here was also the OP on that thread.
    – Seamus
    Aug 13, 2018 at 16:59
  • @Seamus I know, I didn't feel like writing it twice if this is not the cause. Fairly certain it is though.
    – Dirk
    Aug 13, 2018 at 17:06
  • Oh - OK... I assumed the OP would have followed up on that, and updated his post here if it had any value. Possibly a bad assumption on my part :)
    – Seamus
    Aug 13, 2018 at 17:13
  • 1
    @Aurora0001 It says I can click the check mark only after two days. Cool, will do that then. Aug 13, 2018 at 19:02

2 Answers 2

1

I have copy and pasted your test code and runs it from the command line:

rpi:~ $ ./cloud_test.py
Traceback (most recent call last):
  File "./cloud_test.py", line 12, in <module>
    priority = journal.Priority.INFO,
AttributeError: module 'systemd.journal' has no attribute 'Priority'
rpi:~ $

It seems there is no problem with starting the script in rc.local or with a systemd unit file. Instead there may be a problem with your test scripts. Do you really use the same script for bootup and for testing on the command line? Have a look at systemd.journal module what's with the attribute 'Priority'.

6
  • Yes I use the same script for bootup and command line. When running the script manually from the command line, it works absolutely fine without any errors. Aug 13, 2018 at 9:11
  • What is the difference between my command line and yours? I use Raspbian Stretch Lite 2018-06-27 upgraded. Maybe your stderr is redirected? With ./cloud_test.py 2>/dev/null I also get no error message.
    – Ingo
    Aug 13, 2018 at 9:19
  • re "what's with the attribute PRIORITY": From the link you provided: priority is the syslog priority, one of LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG.
    – Seamus
    Aug 13, 2018 at 17:03
  • @Seamus I have seen that also. In a quick test with the copy/pasted program I tried journal.priority.INFO, journal.PRIORITY.INFO, journal.Priority, journal.priority and journal.PRIORITY with no avail.
    – Ingo
    Aug 13, 2018 at 17:18
  • It seems you've been unable to replicate the problem - true? At any rate, the OP may have gotten an answer on another website - see @Dirk's comment to the question
    – Seamus
    Aug 13, 2018 at 17:50
0

This issue was solved by reinstalling systemd module as sudo pip3 install systemd

Intially I did not include sudo while installing systemd.

It can also be solved by including User=pi in the service file.

[Unit]
Description = MESSI v2.0 sensor code
After=multi-user.target

[Service]
Type=idle
ExecStart=/usr/bin/python3 -u cloud_test.py
WorkingDirectory=/home/pi/test_scripts
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

You can view the discussion here too: https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=220304&p=1352497#p1352497

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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