Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我从空闲服务器导入'http.server'时,它可以工作,但是当我运行一个包含'import http.server'的python文件时,出现了一个错误_Python_Http_Python 3.x_Module - Fatal编程技术网

当我从空闲服务器导入'http.server'时,它可以工作,但是当我运行一个包含'import http.server'的python文件时,出现了一个错误

当我从空闲服务器导入'http.server'时,它可以工作,但是当我运行一个包含'import http.server'的python文件时,出现了一个错误,python,http,python-3.x,module,Python,Http,Python 3.x,Module,当我使用: >>> import http.server 在空闲状态下没有任何错误。 但当我使用这段代码时: import http.server from http.server import BaseHTTPRequestHandler from http.server import HTTPServer def run(server_class = HTTPServer, handler_class = BaseHTTPRequestHandler): ser

当我使用:

>>> import http.server
空闲状态下
没有任何错误。
但当我使用这段代码时:

import http.server
from http.server import BaseHTTPRequestHandler
from http.server import HTTPServer

def run(server_class = HTTPServer, handler_class = BaseHTTPRequestHandler):
    server_address = ('', 8000)
    httpd=server_class(server_address, handler_class)
    httpd.serve_forever()


run()
存在如下错误:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2195, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/toton/Projects/http.py", line 1, in <module>
    import http.server
  File "/home/toton/Projects/http.py", line 1, in <module>
    import http.server
ImportError: No module named 'http.server'; 'http' is not a package
回溯(最近一次呼叫最后一次):
文件“”,第2195行,在“查找”和“加载”中解锁
AttributeError:“模块”对象没有属性“\u_路径”
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“/home/toton/Projects/http.py”,第1行,在
导入http.server
文件“/home/toton/Projects/http.py”,第1行,在
导入http.server
ImportError:没有名为“http.server”的模块;'“http”不是一个包

请帮忙

您已将文件命名为
http.py
,因此它将覆盖原始模块
http

解决

  • 将文件名更改为其他名称
  • 删除
    pyc
    文件
  • 再次运行程序