0
votes

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:

 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()

enter image description here

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. I'm using Sublime Text to run it. I tried to do it using Jupyter, but there it gave me another error. I don't know what to do. Thank you for your response.

2

2 Answers

0
votes
(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.

As a very simple debugging step, you could print request_line to see if it's what you expected.

0
votes

I was a problem with type of response because in the tutorial they were using Python 2.7 and in Python 3+ there was a confunsion about the type of variable (byte and string).