【问题标题】:NiFi: Using xml.etree.ElementTree in Python scriptNiFi:在 Python 脚本中使用 xml.etree.ElementTree
【发布时间】:2020-05-22 14:14:12
【问题描述】:

Nifi 1.5.0 我正在尝试在 ExecuteScript 处理器中执行这个 Python 脚本:

import java.io
from org.apache.commons.io import IOUtils
from java.nio.charset import StandardCharsets
from org.apache.nifi.processor.io import StreamCallback
import xml.etree.ElementTree as ET

class PyStreamCallback(StreamCallback):
    def __init__(self):
        pass
    def process (self, inputStream, outputStream):
        xmlRaw = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
        tree = ET.fromstring(xmlRaw)
        root = tree.getroot()
        xmlFix = ET.tostring(root, encoding='utf8', method='xml')
        outputStream.write(bytearray(xmlFix))

flowFile = session.get()
if (flowFile != None):
        #callback = PyStreamCallback(flowFile)
        #session.read(flowFile, callback)
        flowFile = session.write(flowFile, PyStreamCallback())
        session.transfer(flowFile, REL_SUCCESS)
        session.commit()

我有错误:

ExecuteScript[id=3c68eecc-0172-1000-ffff-ffff82be9cc3] Failed to process session due to javax.script.ScriptException: org.xml.sax.SAXException: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser in <script> at line number 21: org.apache.nifi.processor.exception.ProcessException: javax.script.ScriptException: org.xml.sax.SAXException: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser in <script> at line number 21

Jython 不支持 xml.etree.ElementTree 还是 Nifi 配置错误?

【问题讨论】:

    标签: etl apache-nifi


    【解决方案1】:

    在 Nifi 1.5 https://community.cloudera.com/987654321@ 中弃用 Spaxparser2

    【讨论】:

      猜你喜欢
      • 2020-03-23
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      • 2022-11-26
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多