Http protocol Script

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

    Http protocol Script

    Hi,
    I am new to Python and wrote a http protocol script. I got this error please slove this

    my server:::



    import string,cgi,time

    from os import curdir, sep

    from BaseHTTPServer import BaseHTTPRequest Handler, HTTPServer





    class MyHandler(BaseH TTPRequestHandl er):



    def do_GET(self):

    try:
    send_response(2 00)

    send_header('Co ntent-type','text/html')

    send_headers()





    except IOError:

    send_error(404, 'File Not Found: %s' % self.path)


    def xyz():

    send_responce(2 00)
    send_headers('C ontent_type','t ext/html')







    def main():

    try:

    server = HTTPServer(('', 50), MyHandler)

    print 'started httpserver...'

    server.serve_fo rever()

    except KeyboardInterru pt:

    print '^C received, shutting down server'

    server.socket.c lose()



    if __name__ == '__main__':

    main()





    My client:::

    import httplib

    conn=httplib.HT TPConnection('l ocalhost',50)
    conn.request('x yz','index.esp' )
    r=conn.getrespo nse()
    print r.status


    Error I got:::

    localhost.local domain - - [14/Sep/2007 11:43:53] code 501, message Unsupported method ('xyz')
    localhost.local domain - - [14/Sep/2007 11:43:53] "xyz index.esp HTTP/1.1" 501
Working...