Sphinx -python3 -m http.server-FileNotFoundError:[Errno 2]没有这样的文件或目录

问题描述 投票:0回答:1

我的问题-如何找出丢失的文件/目录?

Python3 http服务器在本地提供Sphinx html文件,但随后突然停止提供它们-我在终端中收到此错误-不知道缺少哪个文件/目录?

/pycon-sphinx-tutorial/crawler/docs/_build/html$ python3 -m http.server 8989
Serving HTTP on 0.0.0.0 port 8989 ...
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 60996)
Traceback (most recent call last):
  File "/usr/lib/python3.5/socketserver.py", line 313, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 341, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 354, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.5/socketserver.py", line 681, in __init__
    self.handle()
  File "/usr/lib/python3.5/http/server.py", line 422, in handle
    self.handle_one_request()
  File "/usr/lib/python3.5/http/server.py", line 410, in handle_one_request
    method()
  File "/usr/lib/python3.5/http/server.py", line 645, in do_GET
    f = self.send_head()
  File "/usr/lib/python3.5/http/server.py", line 669, in send_head
    path = self.translate_path(self.path)
  File "/usr/lib/python3.5/http/server.py", line 785, in translate_path
    path = os.getcwd()
FileNotFoundError: [Errno 2] No such file or directory
----------------------------------------
^C
Keyboard interrupt received, exiting.
dhankar@dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs/_build/html$ cd ..
dhankar@dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs/_build$ ls -ltr
total 8
drwxrwxr-x 2 dhankar dhankar 4096 Oct 30 00:19 doctrees
drwxrwxr-x 4 dhankar dhankar 4096 Oct 30 00:19 html
dhankar@dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs/_build$ cd html
dhankar@dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs/_build/html$ ls -ltr
total 36
-rw-rw-r-- 1 dhankar dhankar 3849 Oct 30 00:19 index.html
-rw-rw-r-- 1 dhankar dhankar 3346 Oct 30 00:19 install.html
-rw-rw-r-- 1 dhankar dhankar 3694 Oct 30 00:19 support.html
drwxrwxr-x 2 dhankar dhankar 4096 Oct 30 00:19 _sources
-rw-rw-r-- 1 dhankar dhankar 2629 Oct 30 00:19 genindex.html
-rw-rw-r-- 1 dhankar dhankar 3120 Oct 30 00:19 search.html
drwxrwxr-x 2 dhankar dhankar 4096 Oct 30 00:19 _static
-rw-rw-r-- 1 dhankar dhankar  979 Oct 30 00:19 searchindex.js
-rw-rw-r-- 1 dhankar dhankar  295 Oct 30 00:19 objects.inv
dhankar@dhankar-VPCEB44EN:/media/dhankar/Dhankar_1/a5_test_sphinx/pycon-sphinx-tutorial/crawler/docs/_build/html$ 
python-sphinx
1个回答
0
投票

如您所见,正在从os.getcwd()中引发异常。这将建议您或其他进程删除服务器运行时正在提供文件的目录。如果当前工作目录已删除,则随后对os.getcwd()的调用将引发FileNotFound。例如:

>>> import os
>>> os.mkdir('a')
>>> os.chdir('a')
>>> os.getcwd()
'/blah/blah/blah/a'
>>> os.rmdir(os.getcwd())
>>> os.getcwd()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory

所以我想,不要那样做。

© www.soinside.com 2019 - 2024. All rights reserved.