1

我有一些 PDF 文件,直到几天前我才使用tika.

我没有更改我的代码中的任何内容,但我不再能够通过运行以下代码查看相同 PDF 中的内容:

from tika import parser

raw = parser.from_file('reits.pdf', 'http://localhost:9998/tika')
print(raw['content'])

直到最近,这在最新安装的 tika 上运行良好conda install -c conda-forge tika

问题似乎是Java没有激活。当我查看时出现以下错误metadata

'X-TIKA:EXCEPTION:runtime': 'java.lang.NullPointerException\n\tat

我不确定以下内容是否有帮助,但元数据也返回了:

X-Parsed-By': ['org.apache.tika.parser.DefaultParser','org.apache.tika.parser.pdf.PDFParser']

我该怎么做才能让 tika 重新开始工作?

如果这有帮助:

The full exception stack trace is included below:

org.apache.tika.exception.TikaException: Unexpected RuntimeException from org.apache.tika.parser.pdf.PDFParser@3b75f5cb
    at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:293)
    at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:280)
    at org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:143)
    at org.apache.tika.parser.ParserDecorator.parse(ParserDecorator.java:188)
    at org.apache.tika.parser.DigestingParser.parse(DigestingParser.java:84)
    at org.apache.tika.gui.TikaGUI.handleStream(TikaGUI.java:358)
    at org.apache.tika.gui.TikaGUI.openFile(TikaGUI.java:309)
    at org.apache.tika.gui.ParsingTransferHandler.importFiles(ParsingTransferHandler.java:94)
    at org.apache.tika.gui.ParsingTransferHandler.importData(ParsingTransferHandler.java:77)
    at javax.swing.TransferHandler.importData(TransferHandler.java:827)
    at javax.swing.TransferHandler$DropHandler.drop(TransferHandler.java:1544)
    at java.awt.dnd.DropTarget.drop(DropTarget.java:455)
    at javax.swing.TransferHandler$SwingDropTarget.drop(TransferHandler.java:1282)
    at sun.awt.dnd.SunDropTargetContextPeer.processDropMessage(SunDropTargetContextPeer.java:538)
    at sun.lwawt.macosx.CDropTargetContextPeer.processDropMessage(CDropTargetContextPeer.java:143)
    at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchDropEvent(SunDropTargetContextPeer.java:852)
    at sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(SunDropTargetContextPeer.java:776)
    at sun.awt.dnd.SunDropTargetEvent.dispatch(SunDropTargetEvent.java:48)
    at java.awt.Component.dispatchEventImpl(Component.java:4744)
    at java.awt.Container.dispatchEventImpl(Container.java:2297)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
    at java.awt.LightweightDispatcher.processDropTargetEvent(Container.java:4609)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4471)
    at java.awt.Container.dispatchEventImpl(Container.java:2283)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
    at java.awt.EventQueue$4.run(EventQueue.java:733)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.NullPointerException
    at org.apache.tika.parser.pdf.AbstractPDF2XHTML.extractXMPXFA(AbstractPDF2XHTML.java:209)
    at org.apache.tika.parser.pdf.AbstractPDF2XHTML.endDocument(AbstractPDF2XHTML.java:678)
    at org.apache.pdfbox.text.PDFTextStripper.writeText(PDFTextStripper.java:267)
    at org.apache.tika.parser.pdf.PDF2XHTML.process(PDF2XHTML.java:96)
    at org.apache.tika.parser.pdf.PDFParser.parse(PDFParser.java:174)
    at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:280)
... 44 more

编辑通过遵循这个答案 ,我能够让 Tika 工作

具体来说,我将目录更改为下载 Tika 服务器文件的位置,然后运行: java -jar tika-server-x.x.jar -h 0.0.0.0

一旦我在我的 cmd 行中运行上述内容,服务器就启动了,我的代码工作了,我可以查看content.

如何确保 python 中的 Tika 自动打开服务器以避免这种手动解决方法?是否有我需要设置的环境变量?

4

1 回答 1

0

我遇到了同样的错误。在我的情况下,解决方法是杀死正在运行的进程port 9998,然后重新执行它。

python3在我的谷歌计算引擎实例上运行,不得不重新启动它,发布,不知何故 tika 服务器变得稳定。

以下是修复:

fuser 9998/tcp
fuser -k 9998/tcp
于 2020-11-26T08:58:55.813 回答