【问题标题】:Nifi ExecuteStreamCommand returns UnicodeEncodeErrorNifi ExecuteStreamCommand 返回 UnicodeEncodeError
【发布时间】:2020-04-13 08:29:33
【问题描述】:

我正在通过 ExecuteStreamCommand 在 Nifi 中执行 python 脚本。当我在命令行中运行该文件时,我没有收到任何错误,并且输出是正确的。当我在 Nifi 中运行相同的文件时,我收到一个 unicode 错误。有解决办法吗?

错误日志:

'unicodeencodeerror python 'charmap' codec can't encode charecter '\u221'

我正在保存一个包含多种数据类型的 pandas df。引发错误的代码:

wo_new.to_csv(sys.stdout, encoding='utf-8')

在 Nifi ExecuteStreamCommand 属性中:

命令路径:Python

命令参数:引用 .py 文件的位置

我已经尝试过的事情:

  • 强制 utf-8 编码
  • 强制 windows 编码 cp1252(错误日志显示 anaconda 引用的类型)
  • 通过这两种技术启用 unicode https://vladikk.com/2017/03/30/nifi-unicode/
  • 通过 unicodedata 将 df 规范化为 ascii(此应用程序无法正常工作 - 在列级别以及单个字符串应用时出现 .str 错误)

【问题讨论】:

    标签: python pandas unicode apache-nifi unicode-normalization


    【解决方案1】:

    使用文本对每一列强制使用 utf-8 编码似乎可以解决问题。我不知道为什么在保存输出时应用编码没有成功。我使用了以下代码:

    x.str.encode('utf-8')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-12
      • 2020-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-06
      • 1970-01-01
      相关资源
      最近更新 更多