0

First of all, let me say this is not my script. I need to install an older .deb package. It evidently uses Python 2, but that is deprecated on the system. I have fixed a number of obvious issues, such as adding parentheses to print statements, but this one has me puzzled. I am no expert at Python.

This is the script up to the point where it fails. It looks simple to me, but I don't understand why it is failing. This is unpacked from the .deb file.

rtc.py:

#!/usr/bin/python
import os;

def runCommand(command):
    print (command);
    r = os.popen(command);
    info = r.readlines();
    for line in info:
        print (line);

def updateConfig():
    filename = '/boot/config.txt';
    key = 'dtoverlay';
    value = 'i2c-rtc,pcf8563'
    fr = open(filename,'rb');
    try:
        lines = fr.readlines();
        update = 0;
        newValue = '';
        for line in lines :
            if line and line.count(key) > 0:

At this point, Python complains:

Failed to enable unit: Unit file embest-shutdown.service does not exist.
Failed to enable unit: Unit file embest.service does not exist.
Traceback (most recent call last):
  File "/usr/share/PiDesktop/python/rtc.py", line 81, in <module>
    updateConfig();
    ^^^^^^^^^^^^^^
  File "/usr/share/PiDesktop/python/rtc.py", line 21, in updateConfig
    if line and line.count(key) > 0:
                ^^^^^^^^^^^^^^^
TypeError: argument should be integer or bytes-like object, not 'str'
dpkg: error processing package pidesktop-base (--install):
 installed pidesktop-base package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 pidesktop-base

The service file issues may be spurious. I will look into them later if they persist, but I don't understand why line.count(key) is an issue. Why can't key be a str object?

Note I did try to install the 2to3 utility, but pip complains about it being an externally-managed-environment

This is running on a Raspberry Pi under Raspberry Pi OS Bookworm.

0

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.