2

My flask endpoint is defined as follows;

@app.route('/ATGPollingEngineExceptions',methods=['POST'])
def PollingEngineExceptions(PollingException): 
    response = jsonify(statusCode=httplib.OK)                               
    response.status_code = httplib.OK
     ..
    return response

It accepts a python object class PollingException

PollingException

class PollingException(object):

    def __init__(self,errorcode,errordes,stacktrace,timestamp):
        self.ErrorCode=errorcode
        self.ErrorDescription=errordes
        self.StackTrace=stacktrace
        self.DateTimeStamp=timestamp

In my testcase, I try to POST PollingException,

def test_atg_polling_exception(self):
    status=200
    jsonEncoder = CustomJSONEncoder()      
    a= ATGPollingException('System.OutOfMemoryException','System.OutOfMemoryException','System.OutOfMemoryException','2009-02-15T00:00:00Z')
    headers = {'Content-type': 'application/json'}
    jsonmsg=jsonEncoder.default(a)
    response = requests.post("http://localhost:5000/ATGPollingEngineExceptions",data=a)
    print response.status_code
    assert status not in response.status_code

But Im getting Broken Pipe error,

Exception happened during processing of request from ('127.0.0.1', 62948)
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 321, in process_request
    self.finish_request(request, client_address)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 657, in __init__
    self.finish()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 716, in finish
    self.wfile.close()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 283, in close
    self.flush()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 307, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

At the client end I get TypeError: 'PollingException' object is not iterable

Is that the correct way to POST python object using requests library?

davidism
  • 121,510
  • 29
  • 395
  • 339
Ratha
  • 9,434
  • 17
  • 85
  • 163

0 Answers0