This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: AttributeError: 'NoneType' object has no attribute 'sendall'
Type: compile error Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: blvaralakshmi@gmail.com, steven.daprano
Priority: normal Keywords:

Created on 2018-02-22 06:26 by blvaralakshmi@gmail.com, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg312537 - (view) Author: Varalakshmi (blvaralakshmi@gmail.com) Date: 2018-02-22 06:26
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
msg312541 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-02-22 07:10
Hi, this is for tracking bugs in the Python interpreter and standard library, not asking for help debugging your own code. There's no reason (yet) to believe this error is a bug in Python, you need to debug it first to ensure it is not a bug in your own code before posting it as a bug here.

If you need help debugging your code, try the python-list@python.org mailing list.

If you find that it is not a bug in your code, please re-open this issue.
History
Date User Action Args
2022-04-11 14:58:58adminsetgithub: 77087
2018-02-22 07:10:11steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg312541

resolution: rejected
stage: resolved
2018-02-22 06:26:34blvaralakshmi@gmail.comcreate