我正在尝试使用 python 设置 Tika 进行文本提取。我已经安装Java runtime jre 1.8.0
,安装了 tika ,从这个链接pip install tika==1.23
下载了 tika 服务器 jar 文件,并且如本页所述,我已将变量添加到系统环境变量中。我用命令启动了 tika 服务器,我得到了类似下面的东西TIKA_SERVER_JAR="..tika-server-1.9.jar"
java -jar "..tika-server-1.9.jar"
C:\Users\Administrator>java -jar "C:\Program Files\Java\tika-server-1.9.jar"
Mar 02, 2021 4:29:07 PM org.apache.tika.server.TikaServerCli main
INFO: Starting Apache Tika 1.9 server
Mar 02, 2021 4:29:08 PM org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be http://localhost:9998/
Mar 02, 2021 4:29:08 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: jetty-8.y.z-SNAPSHOT
Mar 02, 2021 4:29:08 PM org.slf4j.impl.JCLLoggerAdapter info
INFO: Started SelectChannelConnector@localhost:9998
Mar 02, 2021 4:29:08 PM org.apache.tika.server.TikaServerCli main
INFO: Started
当我http://localhost:9998/
在浏览器中打开时,它会显示 Tika API 文档。
但是当我尝试使用 python 提取文本时,如下所示。
import tika
from tika import parser
tika.initVM()
text = parser.from_file(r"..somefile.doc")
print(text)
tika 没有按预期工作。它引发了如下异常。这是我在控制台上看到的,仅此而已。
2021-03-02 16:31:03,037 [MainThread ] [WARNI] Tika server returned status: 404
几个月前,我曾经成功地将 tika 与 python 一起使用,但我对我现在缺少的东西一无所知。
编辑:当我运行上面的 python 片段时,我可以在控制台中看到如下所示的详细信息。
Mar 03, 2021 9:37:08 AM org.apache.cxf.jaxrs.utils.JAXRSUtils
findTargetMethod
WARNING: No operation matching request path "/rmeta/text" is found, Relative
Path: /text, HTTP Method: PUT, ContentType: */*, Accept: application/json,.
Please enable FINE/TRACE log level for more details.
Mar 03, 2021 9:37:08 AM
org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
WARNING: javax.ws.rs.ClientErrorException: HTTP 404 Not Found
at org.apache.cxf.jaxrs.utils.SpecExceptions.toHttpException(SpecExceptions.java:117)
at org.apache.cxf.jaxrs.utils.ExceptionUtils.toHttpException(ExceptionUtils.java:166)
at org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:526)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:177)
at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:77)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:261)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:70)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1088)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1024)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Unknown Source)
这是我每次运行 python 脚本提取文本时在控制台上看到的内容。