Specify the full path to access to the script and assing 0755 permissions
-rwxr-xr-x 1 755 asterisk 1.4K Jun 10 17:39 database_lookup.py
exten => 501,1,System(/var/lib/asterisk/agi-bin/database_lookup.py)
Executing [501@test:1] System(“SIP/Aph0ne-00000116”, “/var/lib/asterisk/agi-bin/database_lookup.py”) in new stack
Finally, managed to connect to the database.
I checked to which database sqlite3 was connecting from the script and returned the correct path. The script is in the same directory as the database. I then chose to use the full path in the script and it connected.
Thanks for your help.