昨天通過Python寫了了一段腳本,然后通過crontab將腳本調起來執行,手動執行的時候沒有問題的,但是通過crontab進行調度就執行報錯。
報錯的原因如下:
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)
看到這個報錯第一個想到的應該就是編碼的問題,有人說在Python腳本的前面加上 # coding:utf-8 但是那,加上之后還是報這個錯。
最后通過網上的篇博客找到了答案。
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/
按照上面的操作,Python腳本終於調通了,數據完整的插入到數據庫當中。
解決辦法,在執行Python腳本的時候設置編碼即可,
至此問題得到解決。