我尝试创建BaseHTTPRequestHandler的一个类实例,但收到一条错误消息。下面是我所做的:
>>> from BaseHTTPServer import BaseHTTPRequestHandler
>>> obj=BaseHTTPRequestHandler()
>>> obj.send_response(200)我得到了:
>>> obj=BaseHTTPRequestHandler()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __init__() takes exactly 4 arguments (1 given)你能给我一些建议吗?
发布于 2014-12-18 05:02:52
BaseHTTPRequestHandler的签名如下
class BaseHTTPServer.BaseHTTPRequestHandler(request, client_address, server)问题是你没有提供它需要的值
你可以查看https://docs.python.org/2/library/basehttpserver.html#module-BaseHTTPServer,了解它到底需要什么的详细信息。
正如@iCodez评论的那样,self被视为4个所需参数中的1个,但它是隐式传递的,因此您只需传递另外3个参数
https://stackoverflow.com/questions/27534776
复制相似问题