[英]ValueError: too many values to unpack (expected 3) - WebServer
您好,我正在尝试运行本教程,但是在Python 3中,所以在此行中有此ValueError(要解压缩的值太多(预期为3)),在图片中以蓝色标记或如下所示:
def parse_request(self, text):
request_line = text.splitlines()[0]
request_line = request_line.rstrip('\r\n')
# Break down the request line into components
(self.request_method, # GET
self.path, # /hello
self.request_version # HTTP/1.1
) = request_line.split()
我不知道我在做什么错。 有人可以帮帮我吗? 提示符中的代码还可以,但是当我在Google Chrome中打开localhost:8888/hello
,它在Anaconda Prompt中给了我这个错误。 我正在使用Sublime Text来运行它。 我尝试使用Jupyter进行此操作,但它给了我另一个错误。 我不知道该怎么办。 感谢您的答复。
(self.request_method, # GET
self.path, # /hello
self.request_version # HTTP/1.1
) = request_line.split()
这段代码期望request_line.split()
恰好返回三个部分,但是返回的更多。
作为一个非常简单的调试步骤,您可以打印request_line
以查看它是否符合您的期望。
我对响应的类型存在疑问,因为在本教程中他们使用的是Python 2.7,而在Python 3+中,人们对变量的类型(字节和字符串)感到困惑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.