[英]ValueError: too many values to unpack (expected 3) - WebServer
Hello I'm trying to run this tutorial but in Python 3 so I have this ValueError (too many values to unpack (expected 3)) in this line that is marked in blue in the picture or as you can see below: 您好,我正在尝试运行本教程,但是在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()
I don't know what I'm doing wrong. 我不知道我在做什么错。 Can someone please help me?
有人可以帮帮我吗? The code is okay in the prompt but when I open the
localhost:8888/hello
in Google Chrome it gives me back this error in the Anaconda Prompt. 提示符中的代码还可以,但是当我在Google Chrome中打开
localhost:8888/hello
,它在Anaconda Prompt中给了我这个错误。 I'm using Sublime Text to run it. 我正在使用Sublime Text来运行它。 I tried to do it using Jupyter, but there it gave me another error.
我尝试使用Jupyter进行此操作,但它给了我另一个错误。 I don't know what to do.
我不知道该怎么办。 Thank you for your response.
感谢您的答复。
(self.request_method, # GET
self.path, # /hello
self.request_version # HTTP/1.1
) = request_line.split()
This code expects request_line.split()
to return exactly three parts, but it's returning more than that. 这段代码期望
request_line.split()
恰好返回三个部分,但是返回的更多。
As a very simple debugging step, you could print request_line
to see if it's what you expected. 作为一个非常简单的调试步骤,您可以打印
request_line
以查看它是否符合您的期望。
我对响应的类型存在疑问,因为在本教程中他们使用的是Python 2.7,而在Python 3+中,人们对变量的类型(字节和字符串)感到困惑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.