Disk I/O error when saving files to network hard drives

I wrote a code in pyton to copy a sqlite file to a network hard disk that I see from the system at
Every time I run the python code and try to write to the directory /media/routerhd/DataMeteo/ python I get I/O error if I use a directory inside home/osmc/ instead the file is saved regularly.

I assume it’s a permissions issue I tried with sudo and 777 but to no avail.

Does anyone know what the problem could be and how to fix it? Thank you

What does ls -lah /media/routerhd/DataMeteo/ returns?
How is the share mounted?

Thanks for the reply,
ls -lah /media/routerhd/DataMeteo/ returns the list of files contained in the directory.

The folder is accessible as well as the disk where I have other applications that save the files

osmc@osmc:~/www/Meteo$  ls -lah /media/routerhd/DatiMeteo/
total 0
drwxr-xr-x 2 osmc osmc 0 Jul  3 14:47 .
drwxr-xr-x 2 osmc osmc 0 Jul  2 23:04 ..
-rwxr-xr-x 1 osmc osmc 0 Jul  3 12:16 datimet.sqlite
-rwxr-xr-x 1 osmc osmc 0 Jul  3 11:03 datimet3.sqlite
-rwxr-xr-x 1 osmc osmc 0 Jul  3 14:36 datimet4.sqlite
-rwxr-xr-x 1 osmc osmc 0 Jul  3 14:47 datimet4.sqlite22
drwxr-xr-x 2 osmc osmc 0 Jul  3 10:28 old

the disk is mounted with /etc/fstab

// /media/routerhd cifs noauto,noserverino,x-systemd.automount,username=xxxxx,password=yyyyy,uid=osmc,gid=osmc,iocharset=utf8,noperm,rw 0 0

the python function that creates a sqlite database file on the path /media/routerhd/DataMeteo/ is this:

import sqlite3
import os
import shutil

def create_database(database_path):
    # Verifica se il database esiste gia
    if os.path.exists(database_path):
        print("Il database esiste.")

    # Messaggio di saluto
        # Crea una connessione al database
        conn = sqlite3.connect(database_path)
        # Crea un oggetto "cursor" per eseguire le query
        cursor = conn.cursor()

        # Crea la tabella "meteo" con i campi desiderati
        create_table_query = """
            CREATE TABLE meteo (
                DateTime TEXT,
                OutTemp TEXT,
                OutUmid TEXT,
                InTemp TEXT,
                InUmid TEXT,
                DevPoint TEXT,
                WindTemp TEXT,
                WindSpeed TEXT,
                WindGust TEXT,
                WindDir TEXT,
                RainDif TEXT,
                RainTot TEXT,
                Pressure TEXT

        # Chiudi il cursore

        # Chiudi la connessione al database

        print("Database creato con successo.")
    except sqlite3.Error as e:
        print("Si e verificato un errore:", e)

This file is called db.py and i call the function from another file like this sudo python weather.py
on other locations it works but on the path of the network hard disk /media/routerhd/DataMeteo/ it generates an error and a sqlite corrupted file.

And if you switch it to writing the file to local storage and then moving it to the mount?

Hi, already tried but nothing to do same error. I think it’s a permission problem with the pyton code or sqlite.

Have you tried specifying the permission of the mount instead of using noperm like outlined in this howto…

Thanks already tried but without success…

So if you move/copy the file on the terminal (mv/cp) to the shared folder it throws a error?

if copy files from terminal even without sudo :

osmc@osmc:~/www/Meteo/dati$  cp 2023-07-01.txt /media/routerhd/DatiMeteo/
osmc@osmc:~/www/Meteo/dati$ cp datimet.sqlite /media/routerhd/DatiMeteo/

the files are copied correctly without any Disk I/O errors

osmc@osmc:/media/routerhd/DatiMeteo$ ls
2023-07-01.txt  datimet.sqlite  old

I opened them to check integrity and they are correct.

I’m not sure but I think SQLite 3 has difficulty writing to a network drive, as if the network share doesn’t fully support the I/O operations required by SQLite.