Python EOL while scanning string literal solution, scanningliteral

Source: Internet
Author: User
Tags eol truncated

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.