【发布时间】:2021-02-15 22:33:08
【问题描述】:
我收到了这个错误
Command '['settings.PDF_TO_TEXT', '-layout', 'absolute_file_path', '-']' returned non-zero exit status 1.
这就是我想要实现的目标。
def get_queries(filename, num_queries=3):
scored_chunks = []
absolute_file_path = os.path.join(settings.MEDIA_ROOT, filename)
# pdf_to_text_output = subprocess.check_output([settings.PDF_TO_TEXT, "-layout", absolute_file_path, "-"], shell=true)
pdf_to_text_output = subprocess.check_output(['settings.PDF_TO_TEXT', "-layout", 'absolute_file_path', "-"], shell=True)
try:
text = pdf_to_text_output.decode('utf-8')
except UnicodeDecodeError:
text = pdf_to_text_output.decode('ISO-8859-1')
[..]
我是 Django 和 python 的新手,我尝试了很多解决方案,但没有一个对我有用。因为我不知道它是如何工作的。
环境:
Request Method: POST
Request URL: http://127.0.0.1:8000/index/
Django Version: 3.1.2
Python Version: 3.7.4
这是完整的回溯。
Traceback (most recent call last):
File "C:\Users\Farhana Noureen\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 47,
in inner response = get_response(request)
File "C:\Users\Farhana Noureen\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 179,
in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Farhana Noureen\AppData\Local\Programs\Python\Python37\lib\site-packages\django\views\generic\base.py", line 70,
in view return self.dispatch(request, *args, **kwargs)
File "C:\Users\Farhana Noureen\AppData\Local\Programs\Python\Python37\lib\site-packages\django\views\generic\base.py", line 98,
in dispatch return handler(request, *args, **kwargs)
File "C:\Users\Farhana Noureen\plagtrap\main\views.py", line 302,
in post results = process_homepage_trial(request)
File "C:\Users\Farhana Noureen\plagtrap\main\services.py", line 435,
in process_homepage_trial queries = pdf.get_queries(filename)
File "C:\Users\Farhana Noureen\plagtrap\util\getqueriespertype\pdf.py", line 18,
in get_queries pdf_to_text_output = subprocess.check_output(['settings.PDF_TO_TEXT', "-layout", 'absolute_file_path', "-"], shell=True)
File "C:\Users\Farhana Noureen\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 395,
in check_output **kwargs).stdout
File "C:\Users\Farhana Noureen\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 487,
in run output=stdout, stderr=stderr)
Exception Type: CalledProcessError at /index-trial/
Exception Value: Command '['settings.PDF_TO_TEXT', '-layout', 'absolute_file_path', '-']' returned non-zero exit status 1.
问题出在子进程的 check_output 函数上。我不知道如何纠正这个问题。
【问题讨论】:
标签: python django subprocess