I try to execute INSERT in a DB:

import psycopg2 import pprint import sys def main(): caden = "host='localhost' dbname='my' user='postgres' password='postgrespass'" print(caden) obj = psycopg2.connect(caden) objCursor = obj.cursor() objCursor.execute("INSERT INTO _reference10( _idrref, _version, _marked, _predefinedid, _code, _description) VALUES(%s,%s,%s,%s,%s,%s)", ("\275\233\000\023waU\236\021\345\343\271\273\226\304\366",0 ,false ,"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" , "000000014", "Brazil14")) obj.commit() objCursor.execute("SELECT * FROM _reference10;") registr1=objCursor.fetchall() print(regist1) objCursor.close() obj.close() if __name__ =='__main__': main() 

But an exception occurs:

File "C: \ Python \ Projects \ p.py", line 18 objCursor.execute ("INSERT INTO _reference10 (_idrref, _version, _marked,> _predefinedid, _code, _description) VALUES (% s,% s,% s,% s,% s,% s) ", (" \ 275 \ 233 \ 000 \ 023waU \ 236 \ 021 \ 345 \ 343 \ 271 \ 273 \ 226 \ 304 \ 366 ", 0, false," \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 \ 000 "," 000000014 "," Brazil14 ")) ^ IndentationError: unexpected indent [Finished in 0.1s]

What could be the error?

Closed due to the fact that it is off topic by aleksandr barakin , zRrr , user194374, fori1ton , gecube 6 Jul '16 at 2:09 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - aleksandr barakin, zRrr, community spirit, fori1ton, gecube
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Check the indents on the 18th line, there must be obesity before objCursor.execute (..., an extra space (or tab) started. - And
  • You have there instead of four spaces tab. - andreymal
  • Thank. This is the mistake - Kashton

1 answer 1

From comments:


On the 18th line, instead of four spaces, tabulation is the cause of the error.