Python EOL while scanning string literal solution, scanningliteral
There is a scheduled task in the project. Some table data is obtained every day and uploaded to an external interface. However, there is always an exception recently. I checked the cause today.
First, there is no problem in testing the program locally and in the test environment. Only the online environment will throw an exception in the log. The main cause of the exception is the Data Exception.
However, it is unknown which data has an exception, so the program's output log and data printing are added, and the wrong function and data records are located through several operations.
The exception is as follows:
Copy codeThe Code is as follows:
EOL while scanning string literal: <string>, line 1, pos 7
Google, the cause of this exception is the string, which does not appear in pairs with quotation marks, which is similar to the following situation.
Copy codeThe Code is as follows:
Str ('1)
Traceback (most recent call last ):
File "<string>", line 1, in <fragment>
EOL while scanning string literal: <string>, line 1, pos 7
If this problem does not exist in the program, the problem will come from the records in the database. After investigation, it is found that the maximum length of a field in the database is 65 KB, And the stored data is greater than 65 KB, the entire string is truncated.
The entire string is not a general string, but a dictionary character format, similar to str (dictA)
A key or value of dicA is truncated. For example, it is truncated from {"name": "orangleiu"} to {"name": "orang
Therefore, an error is returned when the retrieved string is converted to the str type.
Added Exception Handling and field growth length to solve the problem.