WHAT IS WRONG WITH MY PYTHON SCRIPT!?
-
I am following along with a tutorial on how to make a webserver. I am using python 2.7.2 and this is the code #!/usr/bin/env python # import sys for handling command line argument # import socket for network communications import sys, socket # hard-wire the port number for safety's sake # then take the names of the host and file from the command line port = 80 host = sys.argv[1] filename = sys.argv[2] # create a socket object called 'c' c = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # connect to the socket c.connect((host, port)) # create a file-like object to read fileobj = c.makefile('r', 0) # Ask the server for the file fileobj.write("GET "+filename+" HTTP/1.0\n\n") # read the lines of the file object into a buffer, buff buff = fileobj.readlines() # step through the buffer, printing each line for line in buff: print line I keep getting the error sys.argv[1] list index out of range What am i doing wrong?
-
Answer:
how are you calling your program? from the command line? Sounds like you didn't give it a value, therefore that indexed position was never created. Should be something like this: ./myFile.py myHost remoteFile
Jared at Yahoo! Answers Visit the source
Related Q & A:
- What's wrong with this PHP Twitter API POST?Best solution by Stack Overflow
- Where can I host my Python script?Best solution by Quora
- What is wrong with this Laravel 5 response?Best solution by Stack Overflow
- What does {!r} mean in Python?Best solution by Stack Overflow
- What's wrong with my yahoo 360 page stat counter?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.