python http protocol

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • allavarapu
    New Member
    • Sep 2007
    • 12

    python http protocol

    Hi
    This is the program .
    [CODE=python]
    import sys, httplib
    showlines = 6
    try:
    servername, filename = sys.argv[1:] # cmdline args?
    except:
    servername, filename = 'starship.pytho n.net', '/index.html'
    print servername, filename
    server = httplib.HTTP(se rvername) # connect to http site/server
    server.putreque st('GET', filename) # send request and headers
    server.putheade r('Accept', 'text/html') # POST requests work here too
    server.endheade rs( ) # as do CGI script filenames
    errcode, errmsh, replyheader = server.getreply ( ) # read reply info headers
    if errcode != 200: # 200 means success
    print 'Error sending request', errcode
    else:
    file = server.getfile( ) # file obj for data received
    data = file.readlines( )
    file.close( ) # show lines with eoln at end
    for line in data[:showlines]: print line, # to save, write data to file

    [/CODE]

    I got this error
    Code:
    starship.python.net /index.html
    Traceback (most recent call last):
      File "http_test.py", line 11, in ?
        server.endheaders()
      File "/usr/lib/python2.3/httplib.py", line 712, in endheaders
        self._send_output()
      File "/usr/lib/python2.3/httplib.py", line 597, in _send_output
        self.send(msg)
      File "/usr/lib/python2.3/httplib.py", line 564, in send
        self.connect()
      File "/usr/lib/python2.3/httplib.py", line 532, in connect
        socket.SOCK_STREAM):
    socket.gaierror: (-2, 'Name or service not known')
    please solve the problem


    thanks
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    I'm not sure if the "http" is required or if you've got the slash in the right place:
    http://starship.python .net/crew/index.html may need:
    "http://starship.python .net/crew/", "index.html " or some other combination thereof.

    Comment

    Working...