第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

sqlite3.InterfaceError:錯(cuò)誤綁定參數(shù)0-可能不受支持的類型

sqlite3.InterfaceError:錯(cuò)誤綁定參數(shù)0-可能不受支持的類型

一只萌萌小番薯 2021-03-28 15:51:00
我正在編寫一個(gè)將爬蟲存儲在sqlite數(shù)據(jù)庫中的數(shù)據(jù)的代理爬網(wǎng)程序,并且我更喜歡通過像cur.execute("insert into test(p) values (?)", (p,))這樣的語句保存一個(gè)復(fù)雜的對象, 然后在這里找到有用的官方文檔。官方文檔中的示例非常有效。但是我有一個(gè)問題。我將官方代碼更改為:import sqlite3import timeclass Proxy:    def __init__(self,ip,port,speed,area,level,active,last_check_time):        self.ip = ip        self.port = port        self.speed = speed        self.area = area        self.level = level        self.active = active        self.last_check_time = last_check_time    def __repr__(self):        return '%s;%s;%s;%s;%s;%d;%d' % (self.ip,self.port,self.speed,self.area,self.level,self.active,self.last_check_time)def adapt_proxy(proxy):    return '%s;%s;%s;%s;%s;%d;%d' % (proxy.ip,proxy.port,proxy.speed,proxy.area,proxy.level,proxy.active,proxy.last_check_time)def convert_proxy(s):    ip,port,speed,area,level,active,last_check_time = map(str, s.split(";"))    return Proxy(ip,port,speed,area,level,int(active),int(last_check_time))# Register the adaptersqlite3.register_adapter(Proxy, adapt_proxy)# Register the convertersqlite3.register_converter("proxy", convert_proxy)p = Proxy('231', '123', '2424','444','555',1,int(time.time()))########################## 1) Using declared typescon = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES)cur = con.cursor()cur.execute("create table test(p proxy)")cur.execute("insert into test(p) values (?)", (p,))cur.execute("select p from test")print "with declared types:", cur.fetchone()[0]cur.close()con.close()######################## 1) Using column namescon = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_COLNAMES)cur = con.cursor()cur.execute("create table test(p)")cur.execute("insert into test(p) values (?)", (p,))cur.execute('select p as "p [proxy]" from test')print "with column names:", cur.fetchone()[0]cur.close()con.close()
查看完整描述

1 回答

?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個(gè)贊

將您的代理聲明更改為:


class Proxy(object):

    # all the stuff before

問題在于您的課程不是“新樣式”課程;繼承object使之成為一體。


請注意文檔中的內(nèi)容:


要適應(yīng)的類型/類必須是新式類,即它必須以object作為其基礎(chǔ)之一。


查看完整回答
反對 回復(fù) 2021-04-05
  • 1 回答
  • 0 關(guān)注
  • 213 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號