-4

Getting error as below:

con.commit()
  ^ SyntaxError: invalid syntax

Here is the code segment for JSON file to MYSQL using python

try:
cursor.execute("""INSERT INTO vehicle (CarYear,make,model,cylinders,VClass,drive,trany,displ,eng_dscr,trans_dscr,mpgData,evMotor,
youSaveSpend,fuleType,fuleType1,barrelsA08,charge120,charge240,city08,city08U,cityA08,cityA08U,cityCD,cityE,cityUF,co2,coA2,co2TailpipeAGpm,
co2TailpipeGpm,comb08,comb08U,combA08,combA08U,combE,combinedCD,combinedUF,engld,feScore,fuelCost08,fuelCostA08,ghgScore,ghgScoreA,highway08,
highway08U,highwayA08,highwayA08U,highwayCD,highwayE,highwayUF,hlv,hpv,id,lv2,lv4,phevBlended,pv2,pv4,CarRange,rangeCity,rangeCityA,rangeHwy,
rangeHwyA,UCity,UCityA,UHighway,UHighwayA,guzzler,tCharger,sCharger,atvType,fuelType2,rangeA,mfrCode,c240Dscr,charge240b,c240bDscr,createdOn,
modifiedOn,startStop,phevCity,phevHwy,phevComb)
VALUES (%s, %s, %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,
%s, %s, %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,%s,%s, %s,    %s,%s, %s,
%s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s, %s,  %s,%s),
(CarYear, make, model, cylinders,VClass, drive, trany, displ, eng_dscr, trans_dscr,mpgData,evMotor,youSaveSpend,fuleType,fuleType1,
barrelsA08,charge120,charge240,city08,city08U,cityA08,cityA08U,cityCD,cityE,cityUF,co2,coA2,co2TailpipeAGpm,co2TailpipeGpm,comb08,
comb08U,combA08,combA08U,combE,combinedCD,combinedUF,engld,feScore,fuelCost08,fuelCostA08,ghgScore,ghgScoreA,highway08,highway08U,
highwayA08,highwayA08U,highwayCD,highwayE,highwayUF,hlv,hpv,id,lv2,lv4,phevBlended,pv2,pv4,CarRange,rangeCity,rangeCityA,rangeHwy,
rangeHwyA,UCity,UCityA,UHighway,UHighwayA,guzzler,tCharger,sCharger,atvType,fuelType2,rangeA,mfrCode,c240Dscr,charge240b,c240bDscr,
createdOn,modifiedOn,startStop,phevCity,phevHwy,phevComb))"""

``

con.commit()

except pymysql.Error as e:
    raise
    sys.exit(1)

finally:
    if con:
        con.close()

NEED HELP Please.. just writing here because of policy

7
  • 3
    you missed the closing bracket ) in cursor.execute Commented Jun 17, 2018 at 15:09
  • 4
    you need to add ) after closing the string """ Commented Jun 17, 2018 at 15:11
  • Now its showing this error!! See I edited again Commented Jun 17, 2018 at 15:12
  • 2
    The use of CAPS in your question and responses here is actually rather irritating. You are not going to get a good response if you keep implying that you're shouting at us. The urgency of your problem is your problem, not ours. Remember, you're asking for help on our time for free. Commented Jun 17, 2018 at 15:16
  • In general it is good to test the query in MySQL first before adding it to Python (or other) script. Commented Jun 17, 2018 at 15:17

1 Answer 1

0

you need to split the SQL string: """ INSERT ... """, the values, something like: """INSERT INTO vehicle (CarYear,make,model,cylinders,VClass,drive,trany,displ,eng_dscr,trans_dscr,mpgData,evMotor, youSaveSpend,fuleType,fuleType1,barrelsA08,charge120,charge240,city08,city08U,cityA08,cityA08U,cityCD,cityE,cityUF,co2,coA2,co2TailpipeAGpm, co2TailpipeGpm,comb08,comb08U,combA08,combA08U,combE,combinedCD,combinedUF,engld,feScore,fuelCost08,fuelCostA08,ghgScore,ghgScoreA,highway08, highway08U,highwayA08,highwayA08U,highwayCD,highwayE,highwayUF,hlv,hpv,id,lv2,lv4,phevBlended,pv2,pv4,CarRange,rangeCity,rangeCityA,rangeHwy, rangeHwyA,UCity,UCityA,UHighway,UHighwayA,guzzler,tCharger,sCharger,atvType,fuelType2,rangeA,mfrCode,c240Dscr,charge240b,c240bDscr,createdOn, modifiedOn,startStop,phevCity,phevHwy,phevComb) VALUES (%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s, %s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s,%s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s)""", (CarYear, make, model, cylinders,VClass, drive, trany, displ, eng_dscr, trans_dscr,mpgData,evMotor,youSaveSpend,fuleType,fuleType1, barrelsA08,charge120,charge240,city08,city08U,cityA08,cityA08U,cityCD,cityE,cityUF,co2,coA2,co2TailpipeAGpm,co2TailpipeGpm,comb08, comb08U,combA08,combA08U,combE,combinedCD,combinedUF,engld,feScore,fuelCost08,fuelCostA08,ghgScore,ghgScoreA,highway08,highway08U, highwayA08,highwayA08U,highwayCD,highwayE,highwayUF,hlv,hpv,id,lv2,lv4,phevBlended,pv2,pv4,CarRange,rangeCity,rangeCityA,rangeHwy, rangeHwyA,UCity,UCityA,UHighway,UHighwayA,guzzler,tCharger,sCharger,atvType,fuelType2,rangeA,mfrCode,c240Dscr,charge240b,c240bDscr, createdOn,modifiedOn,startStop,phevCity,phevHwy,phevComb)

otherwise the whole thing is just a string

Sign up to request clarification or add additional context in comments.

4 Comments

Getting error VALUES (%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s,%s, %s, %s, ^ SyntaxError: invalid syntax
line 127, in <module> createdOn,modifiedOn,startStop,phevCity,phevHwy,phevComb)) ERROR
AttributeError: 'builtin_function_or_method' object has no attribute 'translate'

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.