i have an postgresql database
#p1 = {613309872640, 135117629824, 880993344004, 158175822853, 1073752495240, 216760058760, 447123298313, 912909533578, 762965475336, 306930570381, 972176171275, 6619746319, 343850096144, 764400555409, 546205930000, 528687305491, 404493333779, 77590592280, 855904184346, 936056534938, 661500784670, 141923831071, 562200894625, 567019890466, 832033035811, 72309584292, 364867195430, 190122917676, 144896917811, 580869171253, 1627505081, 627702833596, 644839868222, 172977438016, 1031295913668, 463277927492, 238807296070, 500185745223, 780490132936, 947594928202, 888064501323, 992713674444, 453125481684, 502841610453, 81933315933, 94767975264, 103246266465, 275027812832, 276760003301, 420374924396, 263072530544, 203425700337, 334072272115, 917262638965, 989106489206, 598614815351, 328241935477, 554909676025}
i use this code
connection = psycopg2.connect(user = "...",
password = "...",
host = "...",
port = "...",
database = "...")
c = connection.cursor()
.......
match_ids = set()
for chunk in p[1]:
for id in c.execute("SELECT S.val1 FROM table1 as F JOIN table2 AS S ON F.val2_id=S.val2_id WHERE F.val3=%s and F.val4=%s", (p[0], chunk)):
match_ids.add(id[0])
print(match_ids)
i can use this code on sqlite
but, I get an error when using postgresql
Error: TypeError: 'NoneType' object is not iterable
runcell(0, 'C:/Users/....../test1.py')
{613309872640, 135117629824, 880993344004, 158175822853, 1073752495240, 216760058760, 447123298313, 912909533578, 762965475336, 306930570381, 972176171275, 6619746319, 343850096144, 764400555409, 546205930000, 528687305491, 404493333779, 77590592280, 855904184346, 936056534938, 661500784670, 141923831071, 562200894625, 567019890466, 832033035811, 72309584292, 364867195430, 190122917676, 144896917811, 580869171253, 1627505081, 627702833596, 644839868222, 172977438016, 1031295913668, 463277927492, 238807296070, 500185745223, 780490132936, 947594928202, 888064501323, 992713674444, 453125481684, 502841610453, 81933315933, 94767975264, 103246266465, 275027812832, 276760003301, 420374924396, 263072530544, 203425700337, 334072272115, 917262638965, 989106489206, 598614815351, 328241935477, 554909676025}
Traceback (most recent call last):
File "C:\Users\.....\test1.py", line 208, in <module>
for id in c.execute("SELECT S.val1 FROM table1 as F JOIN table2 AS S ON F.val2_id=S.val2_id WHERE F.val3=%s and F.val4=%s", (p[0], chunk)):
TypeError: 'NoneType' object is not iterable
Try using replacing below snippet with your snippet.
for chunk in p[1]:
for id in c.execute("SELECT S.val1 FROM table1 as F JOIN table2 AS S ON F.val2_id=S.val2_id WHERE F.val3=%s and F.val4=%s", (p[0], chunk)) or []:
match_ids.add(id[0])
print(match_ids)
Actual issue seems that, query can't fetch the result.
Im Facing an error while trying to insert database row values in entry box, but an error is occuring which is given below:
def search_db(self,*args,**kwargs):
with sqlite3.connect('restaurent_pos.db') as db:
c = db.cursor()
c.execute("SELECT * FROM Kitchen_store WHERE Item_name = ?",(self.cb_1.get(),))
rows = c.fetchone()
#result= c.execute(self.cb_1.get(), )
print(rows)
for r in rows:
self.n1 = r[5]
self.n2 = r[6]
self.n3 = r[7]
db.commit()
self.qty_entry.delete(0,END)
self.qty_entry.insert(0, self.n1)
self.rate_entry.delete(0,END)
self.rate_entry.insert(0, self.n2)
self.chef_entry.delete(0,END)
self.chef_entry.insert(0, self.n3)
error:
Traceback (most recent call last):
File "C:\Users\mntech\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "D:\my data\resto.py", line 2002, in search_db
self.n1 = r[5]
TypeError: 'int' object is not subscriptable
It's should work:
print(rows)
self.n1 = rows[5]
self.n2 = rows[6]
self.n3 = rows[7]
Im having a problem inserting a variable into sqlite3 and the variable is hashed.
Here's my code:
if passadefinir == passadefinir2:
maindb.execute("DELETE FROM Password WHERE ID = 'not'")
maindb.execute("INSERT INTO Password(ID) VALUES ('set')")
encriptacao = hashlib.sha1(passadefinir2.encode())
encriptado = (encriptacao.hexdigest(),)
maindb.execute("INSERT INTO Password(Password) VALUES (?)" (encriptado,))
conn.commit()
Here's the error:
Traceback (most recent call last):
File "sqlitetesting.py", line 28, in
maindb.execute("INSERT INTO Password(Password) VALUES (?)" (encriptado,))
TypeError: 'str' object is not callable
Have a nice day :D,
Luis Duarte.
You can substitute using String's format method
password_var = 'your password'
insert_statement = 'INSERT INTO Password(Password) VALUES ({0})'.format('\'' + password_var + '\'')
then run the execute method as:
maindb.execute(insert_statement)
I am trying to create a malware classifier and I am experiencing the error
AttributeError: 'Series' object has no attribute 'Id. Not sure of the error.
Traceback (most recent call last):
File"C:/Users/Afiqmatters/PycharmProjects/MajorProject/feature_extraction.py", line 23, in <module>
rids = [mids.loc[i].Id for i in rchoice]
File "C:\Users\Afiqmatters\Miniconda\lib\site-packages\pandas\core\generic.py", line 2744, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'Id'
Here is the codes I have up to the error.
rs = Random()
rs.seed(1)
trainLabels = pd.read_csv('trainLabels.csv')
#print trainLabels
fids = []
opd = pd.DataFrame()
for label in range(1,10):
mids = trainLabels[trainLabels.Class == label]
mids = mids.reset_index(drop=True)
#print mids
rchoice = [rs.randint(0, len(mids) - 1) for i in range(10)]
print len
#print rchoice
rids = [mids.loc[i].Id for i in rchoice]
The error happens at rids = [mids.loc[i].Id for i in rchoice] and I am not sure of the error.
A sample of what is stored in the trainLabels.csv
Id Class
0A32eTdBKayjCWhZqDOQ 2
mids.loc[i] in this context is a "Series" object which is detailed here
This object type does not have an attribute Series.Id, so that's why you're seeing this error.
Did you mean to call the built-in function id( ) on the object?
rids = [id(mids.loc[i]) for i in rchoice]
When I run this code:
def printPredictions(matches):
pPredictionTable = PrettyTable()
pPredictionTable.field_names = ["Player 1", "Player 2", "Difference", "Winner"]
for match in matches:
p1 = match['teamA']
p2 = match['teamB']
if match['aBeatb'] == True:
pPredictionTable.add_row([match['teamA'], match['teamB'], match['difference'], p1])
else:
pPredictionTable.add_row([match['teamA'], match['teamB'], match['difference'], p2])
print(pPredictionTable)
printPredictions(pmatches)
I get this error:
Traceback (most recent call last):
File "C:\Users\ericr_000\Desktop\PyDev\NPA-2-Rating-System\Rankings.py", line 645, in <module>
printPredictions()
TypeError: 'str' object is not callable
I have pmatches as a separate dictionary, and I don't have the coding skills to fix this issue. (Line 145 is printPredictions(pmatches)
If you're getting 'str' object is not callable when you try to call printPredictions, that means that by the time your program reaches line 645, the name printPredictions was reassigned to a string. Somewhere in your code you have something like
printPredictions = someStringValueGoesHere
You should choose a different name for that variable, or delete the line entirely.
foobar = someStringValueGoesHere