asyncio icon indicating copy to clipboard operation
asyncio copied to clipboard

how to read and write bulk data from a post request

Open anupam587 opened this issue 10 years ago • 3 comments

i am writing a n/w bound application using python asyncio In case a bulk amount of data transferred from client , reader.read(8192) receiving an empty data

please suggest me some way to do in bulk from post request in one shot

following was my code

 def handle_connection(reader, writer):
    data = ""
    while True:
           data_loc =  yield from  reader.readexactly(8192)
           print(data_loc) ### here it is receiving an empty data from client in case of bulk data sent   through post parameter
           if not data_loc:
               break
          data += data_loc.decode('utf-8')

           yield from process_payload(writer, message, 30)

           writer.write_eof()   
           writer.close()


  url = 'not.real.ip.address'
  data = {'symbols': 'GD- US,14174T10,04523Y10,88739910,03209R10,46071F10,77543110,92847N10'}

  loop = asyncio.get_event_loop()
  loop.run_until_complete(echo_server())
  try:
        loop.run_forever()
  finally:
       loop.close()

anupam587 avatar Nov 02 '15 11:11 anupam587

I'm guessing at the top of your file is the first 5 lines of examples/echo_server_tulip.py. How are you generating the "bulk data"? IOW what does your client do? Looking at the code for readexactly() it is really hard to imagine how it would return b'' when called with 8192; it should raise EOFError for a short read.

gvanrossum avatar Nov 02 '15 15:11 gvanrossum

i am completely new to use python asyncio , i am trying to create a n/w bound application which will accept a post request and collect the data from another web api's .

my client is sending a post request which contains json data

ex: data = [{ username: 'uid1', url = 'web.api.address' exprs= 'expr1&&expr2&&expr3', symbols: '56633010,17290810,41308610,05945F10,51384710,74838J10,45168K30' }]

here in symbols i am having a string which contain more then 20000 values (comma seprated)

this post request i am trying to read using yield from reader.readexactly(8192) or yield from reader.read(8192) method

in case when i am sending 100 -110 values in symbols , it is able to read that and print the read data using print(data_loc) but in case of bulk request containing 2000 values in symbols , it is unable to read , even though i raised the limit to ==> reader.read(-1)

anupam587 avatar Nov 02 '15 16:11 anupam587

Maybe you should look into aiohttp? It's for http.

--Guido (mobile) On Nov 2, 2015 8:09 AM, "Anupam Gupta" [email protected] wrote:

i am completely new to use python asyncio , i am trying to create a n/w bound application which will accept a post request and collect the data from another web api's .

my client is sending a post request which contains json data

ex: data = [{ username: 'uid1', url = 'web.api.address' exprs= 'expr1&&expr2&&expr3', symbols: '56633010,17290810,41308610,05945F10,51384710,74838J10,45168K30' }]

here in symbols i am having a string which contain more then 20000 values (comma seprated)

this post request i am trying to read using yield from reader.readexactly(8192) or yield from reader.read(8192) method

in case when i am sending 100 -110 values in symbols , it is able to read that and print the read data using print(data_loc) but in case of bulk request containing 2000 values in symbols , it is unable to read , even though i raised the limit to ==> reader.read(-1)

— Reply to this email directly or view it on GitHub https://github.com/python/asyncio/issues/283#issuecomment-153065550.

gvanrossum avatar Nov 02 '15 16:11 gvanrossum