zoukankan      html  css  js  c++  java
  • 关于Python脚本通过crontab调度的时候报错UnicodeEncodeError: ‘ascii’ codec can’t encode characters in positi的解决方案

    昨天通过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("u6570u636eu5199u5165csvu5f00u59cb")
    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脚本的时候设置编码即可,

    至此问题得到解决。

  • 相关阅读:
    poj 3616 Milking Time
    poj 3176 Cow Bowling
    poj 2229 Sumsets
    poj 2385 Apple Catching
    poj 3280 Cheapest Palindrome
    hdu 1530 Maximum Clique
    hdu 1102 Constructing Roads
    codeforces 592B The Monster and the Squirrel
    CDOJ 1221 Ancient Go
    hdu 1151 Air Raid(二分图最小路径覆盖)
  • 原文地址:https://www.cnblogs.com/gxgd/p/11250002.html
Copyright © 2011-2022 走看看