New submission from Varalakshmi <blvaralaks...@gmail.com>: Hi , I have requirement to simulate http server on particular port we have an application which sends req to that simulated server for that port I need to get that request read the request body Validate the request body and send response back to the appln from the simulated server based on the validation
I want to do all this in robot framework I'm using BaseHTTPServer module to simulate the server my code is as follows #!/usr/bin/python import sys simulator_server_ip=sys.argv[1] simulator_server_port=sys.argv[2] from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from SocketServer import ThreadingMixIn import threading class Handler(BaseHTTPRequestHandler): def do_POST(self): print "getting data section" content_len = int(self.headers.getheader('content-length', 0)) self.req_body = self.rfile.read(content_len) return self.req_body def sendresponse_code(self,code): print "response section" self.send_response(code) self.end_headers() message = threading.currentThread().getName() self.wfile.write(message) self.wfile.write('\n') return class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): """Handle requests in a separate thread.""" if __name__ == '__main__': server = ThreadedHTTPServer((simulator_server_ip,int(simulator_server_port)), Handler) req,c_a=server.get_request() hlr=Handler(req,c_a,server.server_address) print hlr.req_body # this is the request body which needs to be validated outside the code resp_code=input("send the code:") # based on the validation I need to send the response which is handled from outside hlr.sendresponse_code(resp_code) </code> when I run the above code , in send_response section it is failing and I'm getting the following error getting data section {"push-message":"json_data_too_many_parameters_so_not_pasting_the_Data"} send the code:200 response section 10.10.30.50 - - [22/Feb/2018 19:14:44] "POST /pushnotification/v1.0/message HTTP/1.1" 200 - Traceback (most recent call last): File "PNS_200Resp.py", line 38, in <module> hlr.sendresponse_code(resp_code) File "PNS_200Resp.py", line 22, in sendresponse_code self.send_response(code) File "/usr/lib64/python2.6/BaseHTTPServer.py", line 383, in send_response (self.protocol_version, code, message)) File "/usr/lib64/python2.6/socket.py", line 324, in write self.flush() File "/usr/lib64/python2.6/socket.py", line 303, in flush self._sock.sendall(buffer(data, write_offset, buffer_size)) AttributeError: 'NoneType' object has no attribute 'sendall' can some one Please check and let me know what is wrong with the code ---------- components: Library (Lib) messages: 312537 nosy: blvaralaks...@gmail.com priority: normal severity: normal status: open title: AttributeError: 'NoneType' object has no attribute 'sendall' type: compile error versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32906> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com