AttributeError:“bytes”对象在运行Tika解析器时没有属性“close”

2024-09-23 22:29:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用Tika运行一个简单的代码解析行来解析PDF(本例中命名为outputFileName)中的文本。它过去运行时没有错误。我最近让我的笔记本电脑被派到我们的工作IT软件更新,并不得不重新安装Python和导入某些模块(如2019年11月9日发布的Tika 1.22)来运行我的代码。我还从Tika导入了解析器。下面是我得到的代码行和错误消息:

代码:

#分析pdf文件中的文本以使用

pdftext=parser.from_文件(输出文件名)

错误

    AttributeError                            Traceback (most recent call last)
    <ipython-input-14-239522b5ef31> in <module>
          1 #parsing the text out of pdf file to work with
    ----> 2 pdftext = parser.from_file(outputFileName)

    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\tika\parser.py in from_file(filename, serverEndpoint, xmlContent, headers, config_path, requestOptions)

         34     '''
         35     if not xmlContent:
    ---> 36         jsonOutput = parse1('all', filename, serverEndpoint, headers=headers,config_path=config_path, requestOptions=requestOptions)

         37     else:
         38         jsonOutput = parse1('all', filename, serverEndpoint, services={'meta': '/meta', 'text': '/tika', 'all': '/rmeta/xml'},

    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\tika\tika.py in parse1(option, urlOrPath, serverEndpoint, verbose, tikaServerJar, responseMimeType, services, rawResponse, headers, config_path, requestOptions)
        327     headers.update({'Accept': responseMimeType, 'Content-Disposition': make_content_disposition_header(path)})
        328     status, response = callServer('put', serverEndpoint, service, open(path, 'rb'),
    --> 329                                   headers, verbose, tikaServerJar, config_path=config_path, rawResponse=rawResponse, requestOptions=requestOptions)
        330 
        331     if file_type == 'remote': os.unlink(path)

    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\tika\tika.py in callServer(verb, serverEndpoint, service, data, headers, verbose, tikaServerJar, httpVerbs, classpath, rawResponse, config_path, requestOptions)
        544 
        545     resp = verbFn(serviceUrl, encodedData, **effectiveRequestOptions)
    --> 546     encodedData.close() # closes the file reading data
        547 
        548     if verbose:

    AttributeError: 'bytes' object has no attribute 'close'

我还下载了Java8。在

有什么问题吗提卡.py源代码?或者我错过了一些需要安装的东西吗?任何帮助都将不胜感激。在


Tags: path代码inpyconfigverbose错误service
3条回答

只需安装以前版本的tika。我也有同样的问题,这对我很有效。怎样?转到终端并键入pip install tika==1.19

在更新tika python库之后,我也遇到了这个错误,如果您需要一个临时的修复,我建议降级到版本1.19

找到解决方案

请参阅以下GitHub项目,Trofleb在该项目中提出了解决方案:

https://github.com/chrismattmann/tika-python/issues/252

相关问题 更多 >