dbm.open - File does not exist

Viewed 10

Using:

  • python 3.9.2
  • AWS greengrass 2
  • Raspberry Pi

I need to use dbm to write a value from command line when commissioning a thing and then read from that database file when a python greengrass script runs. Logged in as user "pi" I use the following from command line:

sudo runuser -l ggc_user -c 'python3'

and then I set the variable in python:

import dbm
with dbm.open('cache', 'c') as db:
    db['topic_prefix'] = 'testing'

I have confirmed that db['topic_prefix'] using:

sudo runuser -l ggc_user -c 'python3'

and then I read the variable in python:

import dbm
with dbm.open('cache', 'c') as db:
     print(db.get('topic_prefix'))

Now I run this python greengrass script as used ggc_user. Here is a snippet:

with dbm.open('cache', 'r') as db:
    topic = db.get('topic_prefix', b'undefined').encode('ASCII')
    print("Topic prefix set as: " + topic)
    topic = topic + "/" + os.getenv("AWS_IOT_THING_NAME")

I get the error:

error[0]("db file doesn't exist; ".

What am I doing wrong? How can I write a database file that can persist through reboots and be accessible by ggc_user?

0 Answers
Related