hi guys,
could you please advise on the following ?
on the localhost:8900 there is aiohttp server running
when i do a request like (using the python2 module requests) from ipython
requests.get("http://127.0.01:8900/api/bgp/show-route", data={'topo':"switzerland", 'pop':"zrh", 'prefix':"1.1.1.1/32"})
and there is a route defined in the aiohttp server
app.router.add_route("GET", "/api/bgp/show-route", api_bgp_show_route)
which is being handled like
def api_bgp_show_route(request):
pass
the question is: how do i retrieve on server-side the data part of the request ?
meaning
{'topo':"switzerland", 'pop':"zrh", 'prefix':"1.1.1.1/32"}
Does the following snippet solve solve your needs?
def api_bgp_show_route(request):
data = await request.post()
assert data == {'topo':"switzerland", 'pop':"zrh", 'prefix':"1.1.1.1/32"}
great. thanks. could you please help me unpack it ?
data is <MultiDictProxy()> for which i didn't find much info
thanks Andrew
but.. len(data) equals to 0
when i do the same request to a flask app i do not have any issues getting the data
Aahh. Got your problem.
Why do you use GET request with data? Technically it's possible but highly
discouraged.
Also sorry for misleading answer.
In your case you might use await request.json().
On Mon, Sep 12, 2016 at 1:02 PM Nikos Skalis [email protected]
wrote:
thanks Andrew
but.. len(data) equals to 0
when i do the same request to a flask app i do not have any issues getting
the data—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
https://github.com/KeepSafe/aiohttp/issues/1155#issuecomment-246303088,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAVwL31QoLS-1rw3xocHhCjg1g1X5IH-ks5qpSMkgaJpZM4J6GGZ
.
Thanks,
Andrew Svetlov
yes (also changed it to post you are right) :)
Cool!
On Mon, Sep 12, 2016 at 5:03 PM Nikos Skalis [email protected]
wrote:
yes (also changed it to post you are right) :)
—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
https://github.com/KeepSafe/aiohttp/issues/1155#issuecomment-246356654,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAVwLwRHI3oveQ3Ds5Dv-9tZ-0onLsWlks5qpVtpgaJpZM4J6GGZ
.
Thanks,
Andrew Svetlov
@asvetlov
I am trying to send encoded image using the below code, but I couldn't get back the same at the aioHttp server side.
CLIENT SIDE
import asyncio
import random
import requests
async def sendreq(buffer):
jpg_as_text = base64.b64encode(buffer)
async with session.post(url, json=json.dumps({'img': str(jpg_as_text)})) as resp:
print(resp.status)
print(await resp.text())
async def main():
tasks = []
b64buffer = ' opencv will fill this value.'
for i in range(10):
tasks.append(asyncio.ensure_future(sendreq(b64buffer)))
await asyncio.gather(*tasks)
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(main())
finally:
loop.close()
SERVER SIDE:
async def identify_faces(request):
try:
jpg_as_text = await request.json()
# I AM GETTING ERROR HERE. I DONT KNOW HOW TO READ THE B64IMAGE DATA
imdata = json.load(jpg_as_text)
jpg_original = base64.b64decode(imdata['img'])
jpg_as_np = np.frombuffer(jpg_original, dtype=np.uint8)
except Exception as e:
print(e)
# Bad path where name is not set
response_obj = { 'status' : 'failed', 'reason': str(e) }
# return failed with a status code of 500 i.e. 'Server Error'
return web.Response(text=json.dumps(response_obj), status=200)
please advise me, HOW TO SEND A ENCODED IMAGE and RX AT THE SERVER SIDE?
Please help me, bcz since 2 days I am hitting my head.
Most helpful comment
Aahh. Got your problem.
Why do you use GET request with data? Technically it's possible but highly
discouraged.
Also sorry for misleading answer.
In your case you might use
await request.json().On Mon, Sep 12, 2016 at 1:02 PM Nikos Skalis [email protected]
wrote: