0

I create a web proxy server and try to parse the url from the header but I get a problem with split()

def proxy_thread(connectionSocket,addr):

    request = connectionSocket.recv(Buffer)

    GETREQ = request.decode('utf-8', 'ignore').split('\r\n')[0]

    print ("Test " + GETREQ)

    url = GETREQ.split(" ")[1]

Here is the Traceback: Unhandled exception in thread started by Traceback (most recent call last): File "C:\Users\dangt\Desktop\cheg.py", line 62, in proxy_thread url = GETREQ.split(" ")[1] IndexError: list index out of range

  • could you give what is in GETREQ? – Joshua Varghese Apr 16 '20 at 04:19
  • "List index out of range" for index [1] clearly indicates your list contains only 1 element. Try debugging whether `GETREQ` contains any `" "` or not. – CodeTalker Apr 16 '20 at 04:20
  • This is what is in GETREQ "CONNECT www.google.com:443 HTTP/1.1" it has 3 elements. I can print out url. it is "www.google.com:443" but it still has Error: list index out of range – Dang Truong Apr 16 '20 at 04:38

0 Answers0