This is the error I get:
Traceback (most recent call last):
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 435, in eval_code
.run(globals, locals)File "/lib/python3.10/site-packages/_pyodide/_base.py", line 304, in run
coroutine = eval(self.code, globals, locals)File "", line 3, in
File "/home/pyodide/connection_sqlite3.py", line 45, in returnGeral
data = cursor.execute(r"SELECT * FROM tabela;")AttributeError: 'NoneType' object has no attribute 'execute'
A lot of the code in connection_sqlite3 needs work, it's just I don't understand where is the error comes from.
I try the Python code alone with a database, and it works, but when connected with html then this error appeared.
HTML markup:
type <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>index</title>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<link rel="stylesheet" type="text/css" href="style/style.css">
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<py-config>
[[fetch]]
from = 'scripts/'
files = ['connection_sqlite3.py']
</py-config>
<py-script src="scripts/main.py"></py-script>
<div id="principal">
<div id="navegation">
<input placeholder="teste" type="text">
<button py> search </button>
</div>
<div id="table">
</div>
</div>
</body>
</html> here
main.py
file
import connection_sqlite3 as sql
sql.returnGeral()
connection_sqlite3.py
file
import sqlite3
from sqlite3 import Error
data = 'data/tutorial.db'
#query para criacao de tabelas
def templates(arquivo):
raw = open(arquivo)
edited = raw.read()
return edited
#funcoes gerais
def connection():
try:
conn = sqlite3.connect(data)
cursor = conn.cursor()
return conn
except Error as e:
print(f"{e}, and failed in the line 14")
def createTable(archive):
try:
conn = connection()
cursor = conn.cursor()
cursor.execute(archive)
except Error as e:
print(f"{e}, error in the line 23")
def insertData(param):
try:
cursor = connection()
cursor.execute(param)
conn = connection()
conn.commit()
print(fr"{param} was inserted in the table" )
except Error as e:
print(f"{e}, failed at line 41")
def returnGeral():
try:
connection()
cursor = connection()
data = cursor.execute(r"SELECT * FROM tabela;")
raw = data.fetchall()
for i in raw:
print(i)
return data
except Error as e:
print(f"{e}, error in the line 34")
def execute(param):
try:
conn = connection(1)
cursor = connection(2)
cursor.execute(param)
conn.commit()
print(f'{param}, was executed successfully')
except Error as e:
print(f"{e} error in line 64")
I was trying to create a database and link it with pyscrit to insert and return data in a web server, but for now it's just the local part.