从python读取txt导入数据库表中,flask插入数据库遭

2019-12-23 08:44栏目:网络编程
TAG:

这是出错的代码foriinf: i=i.strip() i=i.strip("[]") i_list=i.split(',') foraini_list: if(a==i_list[0]): val=("a[1:-1]") else: val=("a[2:-1]") cursor.executemany(sql,val) //这一行报错f.close()cursor.close()conn.commit()conn.close()print("over")这个是报的错C:UsersabcAppDataLocalProgramsPythonPython36python.exeD:/实验室/untitled2/2.pyConnecttotheDatebase....Traceback(mostrecentcalllast): File"D:/实验室/untitled2/2.py",line17,inmodule cursor.executemany(sql,val) File"srcpymssql.pyx",line476,inpymssql.Cursor.executemany File"srcpymssql.pyx",line450,inpymssql.Cursor.execute File"src_mssql.pyx",line1064,in_mssql.MSSQLConnection.execute_query File"src_mssql.pyx",line1095,in_mssql.MSSQLConnection.execute_query File"src_mssql.pyx",line1212,in_mssql.MSSQLConnection.format_and_run_query File"src_mssql.pyx",line1234,in_mssql.MSSQLConnection.format_sql_command File"src_mssql.pyx",line1914,in_mssql._substitute_paramsTypeError:expectedstringorbytes-likeobjectProcessfinishedwithexitcode1求大神解答,怎么才能正确运行把数据导进去

flask插入数据库遇到问题FLASK_APP=app.pyFLASK_ENV=developmentFLASK_DEBUG=0InfolderD:/我的编程/flaskD:VirtualenvvenvScriptspython.exe-mflaskrun*ServingFlaskapp"app.py"*Environment:development*Debugmode:off*Runningon(PressCTRL+Ctoquit)[2019-12-0917:29:36,658]ERRORinapp:Exceptionon/MovieUpload[POST]Traceback(mostrecentcalllast):File"srcpymssql.pyx",line448,inpymssql.Cursor.executeFile"src_mssql.pyx",line1064,in_mssql.MSSQLConnection.execute_queryFile"src_mssql.pyx",line1095,in_mssql.MSSQLConnection.execute_queryFile"src_mssql.pyx",line1228,in_mssql.MSSQLConnection.format_and_run_queryFile"src_mssql.pyx",line1639,in_mssql.check_cancel_and_raiseFile"src_mssql.pyx",line1683,in_mssql.maybe_raise_MSSQLDatabaseException_mssql.MSSQLDatabaseException:(8106,b"Table'video'doesnothavetheidentityproperty.CannotperformSEToperation.DB-Liberrormessage20018,severity16:nGeneralSQLServererror:CheckmessagesfromtheSQLServern")Duringhandlingoftheaboveexception,anotherexceptionoccurred:Traceback(mostrecentcalllast):File"D:Virtualenvvenvlibsite-packagessqlalchemyenginebase.py",line1318,in_cursor_executeself.dialect.do_execute(cursor,statement,parameters,context)File"D:Virtualenvvenvlibsite-packagessqlalchemyenginedefault.py",line581,indo_executecursor.execute(statement,parameters)File"srcpymssql.pyx",line468,inpymssql.Cursor.executepymssql.OperationalError:(8106,b"Table'video'doesnothavetheidentityproperty.CannotperformSEToperation.DB-Liberrormessage20018,severity16:nGeneralSQLServererror:CheckmessagesfromtheSQLServern")Theaboveexceptionwasthedirectcauseofthefollowingexception:Traceback(mostrecentcalllast):File"C:UsersAdministratorAppDataLocalProgramsPythonPython37Libsite-packagesflaskapp.py",line2446,inwsgi_appresponse=self.full_dispatch_request()File"C:UsersAdministratorAppDataLocalProgramsPythonPython37Libsite-packagesflaskapp.py",line1951,infull_dispatch_requestrv=self.handle_user_exception(e)File"C:UsersAdministratorAppDataLocalProgramsPythonPython37Libsite-packagesflaskapp.py",line1820,inhandle_user_exceptionreraise(exc_type,exc_value,tb)File"C:UsersAdministratorAppDataLocalProgramsPythonPython37Libsite-packagesflask_compat.py",line39,inreraiseraisevalueFile"C:UsersAdministratorAppDataLocalProgramsPythonPython37Libsite-packagesflaskapp.py",line1949,infull_dispatch_requestrv=self.dispatch_request()File"C:UsersAdministratorAppDataLocalProgramsPythonPython37Libsite-packagesflaskapp.py",line1935,indispatch_requestreturnself.view_functions[rule.endpoint](**req.view_args)File"D:我的编程flaskapp.py",line213,inMovieUploadmod.Tablevideo.InsertTablevideo(videoid,select,name,'static/'+thepath1,grade,'static/'+thepath2,about,cast,dirctor)File"D:我的编程flaskmod.py",line59,inInsertTablevideosession.add(video)File"c:usersadministratorappdatalocalprogramspythonpython37Libcontextlib.py",line119,in__exit__next(self.gen)File"D:我的编程flaskmod.py",line123,insession_scopesession.commit()File"D:Virtualenvvenvlibsite-packagessqlalchemyormsession.py",line1027,incommitself.transaction.commit()File"D:Virtualenvvenvlibsite-packagessqlalchemyormsession.py",line494,incommitself._prepare_impl()File"D:Virtualenvvenvlibsite-packagessqlalchemyormsession.py",line473,in_prepare_implself.session.flush()File"D:Virtualenvvenvlibsite-packagessqlalchemyormsession.py",line2470,influshself._flush(objects)File"D:Virtualenvvenvlibsite-packagessqlalchemyormsession.py",line2608,in_flushtransaction.rollback(_capture_exception=True)File"D:Virtualenvvenvlibsite-packagessqlalchemyutillanghelpers.py",line68,in__exit__compat.reraise(exc_type,exc_value,exc_tb)File"D:Virtualenvvenvlibsite-packagessqlalchemyutilcompat.py",line153,inreraiseraisevalueFile"D:Virtualenvvenvlibsite-packagessqlalchemyormsession.py",line2568,in_flushflush_context.execute()File"D:Virtualenvvenvlibsite-packagessqlalchemyormunitofwork.py",line422,inexecuterec.execute(self)File"D:Virtualenvvenvlibsite-packagessqlalchemyormunitofwork.py",line589,inexecuteuow,File"D:Virtualenvvenvlibsite-packagessqlalchemyormpersistence.py",line245,insave_objinsert,File"D:Virtualenvvenvlibsite-packagessqlalchemyormpersistence.py",line1084,in_emit_insert_statementsc=cached_connections[connection].execute(statement,multiparams)File"D:Virtualenvvenvlibsite-packagessqlalchemyenginebase.py",line982,inexecutereturnmeth(self,multiparams,params)File"D:Virtualenvvenvlibsite-packagessqlalchemysqlelements.py",line287,in_execute_on_connectionreturnconnection._execute_clauseelement(self,multiparams,params)File"D:Virtualenvvenvlibsite-packagessqlalchemyenginebase.py",line1101,in_execute_clauseelementdistilled_params,File"D:Virtualenvvenvlibsite-packagessqlalchemyenginebase.py",line1180,in_execute_contextcontext.pre_exec()File"D:Virtualenvvenvlibsite-packagessqlalchemydialectsmssqlbase.py",line1472,inpre_execself,File"D:Virtualenvvenvlibsite-packagessqlalchemyenginebase.py",line1321,in_cursor_executee,statement,parameters,cursor,contextFile"D:Virtualenvvenvlibsite-packagessqlalchemyenginebase.py",line1476,in_handle_dbapi_exceptionutil.raise_from_cause(sqlalchemy_exception,exc_info)File"D:Virtualenvvenvlibsite-packagessqlalchemyutilcompat.py",line398,inraise_from_causereraise(type(exception),exception,tb=exc_tb,cause=cause)File"D:Virtualenvvenvlibsite-packagessqlalchemyutilcompat.py",line152,inreraiseraisevalue.with_traceback(tb)File"D:Virtualenvvenvlibsite-packagessqlalchemyenginebase.py",line1318,in_cursor_executeself.dialect.do_execute(cursor,statement,parameters,context)File"D:Virtualenvvenvlibsite-packagessqlalchemyenginedefault.py",line581,indo_executecursor.execute(statement,parameters)File"srcpymssql.pyx",line468,inpymssql.Cursor.executesqlalchemy.exc.OperationalError:(pymssql.OperationalError)(8106,b"Table'video'doesnothavetheidentityproperty.CannotperformSEToperation.DB-Liberrormessage20018,severity16:nGeneralSQLServererror:CheckmessagesfromtheSQLServern")[SQL:SETIDENTITY_INSERTvideoON](Backgroundonthiserrorat:)127.0.0.1--[09/Dec/201917:29:36]"POST/MovieUploadHTTP/1.1"500-

版权声明:本文由澳门新葡亰平台游戏发布于网络编程,转载请注明出处:从python读取txt导入数据库表中,flask插入数据库遭