I have flask code in helloflask.py and abcd.py in the same folder:
import abcd as abc
@app.route("/ddata")
def stuff1():
p=abc.run('somefile.txt')
return json.dumps(p)
abcd.py has following code
connection = sqlite3.connect('C:\\Users\me\Desktop\Python\my.db')
cursor=connection.cursor()
def dbcall(ip_rel,c_mac):
sql="select count(*) from myDB"
cursor.execute(sql)
row=cursor.fetchone()
count =row[0]
return count #I am returning a list here in my original code
When I run helloflask.py
I get following error while retrieving rows:
ERROR:
File "C:\Users\mvahuje\Desktop\Python\Application\Dsharkclass.py", line 25, in dbcall cursor.execute(sql) ProgrammingError: SQLite objects created in a thread can only be used in that sa me thread.The object was created in thread id 15108 and this is thread id 14488
This has something to do with thread permissions sqlite3
. But I am not sure what could I do additionally to get it working.
Individually out abcd.py
works perfectly fine when called into other code.