Unlink of File i 1_tutor/iplusone/src/db.sqlite3 Failed. Should I Try Again?
1. Issues:
I have been learning python data acquisition these days, and the crawled information is part of the data of 250 movies of Douban's top250. An mistake occurred when storing all the data in the movie250 table of the database, every bit shown in the following figure:
I found that there are a full of 250 movie data, and an error was reported when the eighth i was entered, as shown in the effigy below:
Therefore, information technology can be inferred that in that location is a problem with the sql statement of the eighth flick: cur.execute(sql). Print each line of sql statement, debug to the stop of the eighth movie, equally shown in the figure beneath
It feels that it is a problem with the sql argument, and then I put the sql statement of the eighth picture show into the database console to execute it, and it turned out to be an error in the sql statement:
Advisedly find the sql statement and plant that: it turns out to beapostrophe Caused by improper use of
insert into movie250 (info_link,pic_link,c_name,e_name,score,rated,intro,info) values ( 'https://movie.douban.com/field of study/1295124/' , 'https://img2.doubanio.com/view/photo/s_ratio_poster/public/p492406163.jpg' , 'Schindler's List' , ' Schindler'due south Listing',' ix.5 ',' 834850 ','To relieve one person is to save the whole world ','Director: Steven Spielberg Starring: Liam Neeson. . .1993 U.Due south. Story History State of war')
There is 1 detail in the data: the English name of the movie:' Schindler'south List', which was originallySchindler'due south ListIs a whole, but because the data has a' Leading to inconsistent matching of single quotes.
2. Solution
As long every bit the 'Schindler'due south Listing' is changed to" Schindler's List", the inner single quotation mark will non match the outer double quotation marker.
# v. Store data ---- DataBase def save_data2 (datalist, db_path) : # four.1 Anyhow, there is a database init_db(db_path) # Insert dynamic data conn = sqlite3.connect(db_path) cur = conn.cursor( ) for data in datalist: for alphabetize in range ( len (data) ) : # Enclose each detail of a line of movies in double quotes ---! ! ! Previously reported an mistake with single quotes # data[alphabetize] = "'" + data[alphabetize] + "'" ----> An error was reported earlier! ! data[index] = '"' + information[index] + '"' sql = ''' insert into movie250 (info_link,pic_link,c_name,e_name,score,rated,intro,info) values (%s) ''' % ( "," .bring together(information) ) print (sql) cur.execute(sql) conn.commit( ) cur.close( ) conn.close( )
Delete the previous database and run the plan over again to view:
The control output is normal, and all data is entered in the movie250 tabular array of the database.
View the movie250 tabular array in the database, and also impress to 250 to end:
Source: https://programmersought.com/article/72417510264/
Postar um comentário for "Unlink of File i 1_tutor/iplusone/src/db.sqlite3 Failed. Should I Try Again?"