About Python script via crontab scheduled time error UnicodeEncodeError: 'ascii' codec can not encode characters in positi solutions

Yesterday Python by writing a script for a while, and then tune up crontab script execution, when performed manually no problem, but the scheduling is executed by crontab error.

The reason given is as follows:

Traceback (most recent call last):
  File "/opt/data-integration/workspace/rs_etl/pyscript/get_mobine_supplier.py", line 69, in <module>
    print("\u6570\u636e\u5199\u5165csv\u5f00\u59cb")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)

Should see the problem with this is that the coding error first thought, it was said in front of the Python script plus # coding: utf-8 but that, after this newspaper plus or wrong.

Finally, through the Internet blog post to find the answer.

https://jeffliz.wordpress.com/2019/04/16/python3-%E8%A7%A3%E5%86%B3unicodeencodeerror-ascii-codec-cant-encode-characters-%E9%97%AE%E9%A2%98/

According to the above operation, Python finally transferred through the script, data integrity is inserted into the database.

Solutions set the encoding when you can execute Python scripts,

So far the problem is resolved.

Guess you like

Origin www.cnblogs.com/gxgd/p/11250002.html