Получаю ошибку на esp8266. AttributeError 'NoneType' object has no attribute 'func'

Я очень долго искал и не мог найти никакой информации. почему я получаю эту ошибку. Проверяю код на pycharm, все правильно. на прошивке микропитона esp 8266 выдает ошибку. (с Тонни IDE)

main.py

        import sqlite3

def wifi_net():
    db = sqlite3.connect(r'in.db')
    wifi_setings = '1', input("id"), input("pass")
    cur = db.cursor()
    cur.execute("""CREATE TABLE IF NOT EXISTS wifi_settings(
        sn INTEGER PRIMARY KEY ,
        wifi_ssid TEXT ,
        wifi_pass TEXT);""")
    cur.execute("INSERT OR REPLACE INTO wifi_settings VALUES(?, ?, ?);", wifi_setings)
    db.commit()
    cur.execute("SELECT * FROM wifi_settings;")
    wireless = cur.fetchone()

    ssid = wireless[2]
    password = wireless[3]
    print(ssid, password)

    station = network.WLAN(network.STA_IF)
    station.active(True)
    station.connect(ssid, password)
    while station.isconnected() == False:
        pass
    print('Connection successful')
    print(station.ifconfig())


wifi_net()

SQLite.py

import sys
import ffilib


sq3 = ffilib.open("libsqlite3")

sqlite3_open = sq3.func("i", "sqlite3_open", "sp")
#int sqlite3_close(sqlite3*);
sqlite3_close = sq3.func("i", "sqlite3_close", "p")
#int sqlite3_prepare(
#  sqlite3 *db,            /* Database handle */
#  const char *zSql,       /* SQL statement, UTF-8 encoded */
#  int nByte,              /* Maximum length of zSql in bytes. */
#  sqlite3_stmt **ppStmt,  /* OUT: Statement handle */
#  const char **pzTail     /* OUT: Pointer to unused portion of zSql */
#);
sqlite3_prepare = sq3.func("i", "sqlite3_prepare", "psipp")
#int sqlite3_finalize(sqlite3_stmt *pStmt);
sqlite3_finalize = sq3.func("i", "sqlite3_finalize", "p")
#int sqlite3_step(sqlite3_stmt*);
sqlite3_step = sq3.func("i", "sqlite3_step", "p")
#int sqlite3_column_count(sqlite3_stmt *pStmt);
sqlite3_column_count = sq3.func("i", "sqlite3_column_count", "p")
#int sqlite3_column_type(sqlite3_stmt*, int iCol);
sqlite3_column_type = sq3.func("i", "sqlite3_column_type", "pi")
sqlite3_column_int = sq3.func("i", "sqlite3_column_int", "pi")
# using "d" return type gives wrong results
sqlite3_column_double = sq3.func("d", "sqlite3_column_double", "pi")
sqlite3_column_text = sq3.func("s", "sqlite3_column_text", "pi")
#sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*);
# TODO: should return long int
sqlite3_last_insert_rowid = sq3.func("i", "sqlite3_last_insert_rowid", "p")
#const char *sqlite3_errmsg(sqlite3*);
sqlite3_errmsg = sq3.func("s", "sqlite3_errmsg", "p")

# Too recent
##const char *sqlite3_errstr(int);
#sqlite3_errstr = sq3.func("s", "sqlite3_errstr", "i")


SQLITE_OK         = 0
SQLITE_ERROR      = 1
SQLITE_BUSY       = 5
SQLITE_MISUSE     = 21
SQLITE_ROW        = 100
SQLITE_DONE       = 101

SQLITE_INTEGER  = 1
SQLITE_FLOAT    = 2
SQLITE_TEXT     = 3
SQLITE_BLOB     = 4
SQLITE_NULL     = 5


class Error(Exception):
    pass


def check_error(db, s):
    if s != SQLITE_OK:
        raise Error(s, sqlite3_errmsg(db))


class Connections:

    def __init__(self, h):
        self.h = h

    def cursor(self):
        return Cursor(self.h)

    def close(self):
        s = sqlite3_close(self.h)
        check_error(self.h, s)


class Cursor:

    def __init__(self, h):
        self.h = h
        self.stmnt = None

    def execute(self, sql, params=None):
        if params:
            params = [quote(v) for v in params]
            sql = sql % tuple(params)
        print(sql)
        b = bytearray(4)
        s = sqlite3_prepare(self.h, sql, -1, b, None)
        check_error(self.h, s)
        self.stmnt = int.from_bytes(b, sys.byteorder)
        #print("stmnt", self.stmnt)
        self.num_cols = sqlite3_column_count(self.stmnt)
        #print("num_cols", self.num_cols)
        # If it's not select, actually execute it here
        # num_cols == 0 for statements which don't return data (=> modify it)
        if not self.num_cols:
            v = self.fetchone()
            assert v is None
            self.lastrowid = sqlite3_last_insert_rowid(self.h)

    def close(self):
        s = sqlite3_finalize(self.stmnt)
        check_error(self.h, s)

    def make_row(self):
        res = []
        for i in range(self.num_cols):
            t = sqlite3_column_type(self.stmnt, i)
            #print("type", t)
            if t == SQLITE_INTEGER:
                res.append(sqlite3_column_int(self.stmnt, i))
            elif t == SQLITE_FLOAT:
                res.append(sqlite3_column_double(self.stmnt, i))
            elif t == SQLITE_TEXT:
                res.append(sqlite3_column_text(self.stmnt, i))
            else:
                raise NotImplementedError
        return tuple(res)

    def fetchone(self):
        res = sqlite3_step(self.stmnt)
        #print("step:", res)
        if res == SQLITE_DONE:
            return None
        if res == SQLITE_ROW:
            return self.make_row()
        check_error(self.h, res)


def connect(fname):
    b = bytearray(4)
    sqlite3_open(fname, b)
    h = int.from_bytes(b, sys.byteorder)
    return Connections(h)


def quote(val):
    if isinstance(val, str):
        return "'%s'" % val
    return str(val)

ffilib.py

import sys
try:
    import ffi
except ImportError:
    ffi = None

_cache = {}

def open(name, maxver=10, extra=()):
    if not ffi:
        return None
    try:
        return _cache[name]
    except KeyError:
        pass
    def libs():
        if sys.platform == "linux":
            yield '%s.so' % name
            for i in range(maxver, -1, -1):
                yield '%s.so.%u' % (name, i)
        else:
            for ext in ('dylib', 'dll'):
                yield '%s.%s' % (name, ext)
        for n in extra:
            yield n
    err = None
    for n in libs():
        try:
            l = ffi.open(n)
            _cache[name] = l
            return l
        except OSError as e:
            err = e
    raise err

def libc():
    return open("libc", 6)

# Find out bitness of the platform, even if long ints are not supported
# TODO: All bitness differences should be removed from micropython-lib, and
# this snippet too.
bitness = 1
v = sys.maxsize
while v:
    bitness += 1
    v >>= 1

в этом примере я хотел создать таблицу базы данных и записать туда настройки от вайфая. Далее я создам веб-страницу для добавления настроек в базу данных.


Ответы (0 шт):