Freenove / Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi

Apply to FNK0043
Other
133 stars 148 forks source link

Client fails to start (FileNotFoundError: [Errno 2] No such file or directory: 'IP.txt') #45

Open sjuk opened 6 months ago

sjuk commented 6 months ago

Client failed to start after a fresh git clone https://github.com/Freenove/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi.

Expected: Client starts.

Instead: Client failed to start.

Output: ("LANG=C" is to force English language. The result is the same without, only in German language.)

~/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Client$ LANG=C python Main.py 
QFont::setPointSize: Point size <= 0 (-1), must be greater than 0
QFont::setPointSize: Point size <= 0 (-1), must be greater than 0
QFont::setPointSize: Point size <= 0 (-1), must be greater than 0
QFont::setPointSize: Point size <= 0 (-1), must be greater than 0
Traceback (most recent call last):
  File "/home/sjuk/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Client/Main.py", line 823, in <module>
    myshow=mywindow()
  File "/home/sjuk/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Client/Main.py", line 29, in __init__
    file = open('IP.txt', 'r')
FileNotFoundError: [Errno 2] No such file or directory: 'IP.txt'

Root cause: There is a file called 'ip.txt' instead of 'IP.txt'. Note that linux is case sensitive.

Workaround: Rename ip.txt file to IP.txt without changing code.

Solution: Change code handling the case of missing text file.

fire-eggs commented 5 months ago

The repository needs to be corrected to rename 'ip.txt' to 'IP.txt'.

Ideally, the project should use python standard library functionality such as configparser rather than this ad-hoc mechanism.

fire-eggs commented 5 months ago

Better yet, add exception handling in Main.py, lines 29-31:

        file = open('IP.txt', 'r')
        self.IP.setText(str(file.readline()))
        file.close()

to:

        try:
            file = open('IP.txt', 'r')
            self.IP.setText(str(file.readline()))
            file.close()
        except:
            pass