Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how-to retrieve the data (body) in aiohttp server from requests.get #1155

Closed
nskalis opened this issue Sep 11, 2016 · 8 comments
Closed

how-to retrieve the data (body) in aiohttp server from requests.get #1155

nskalis opened this issue Sep 11, 2016 · 8 comments

Comments

@nskalis
Copy link

nskalis commented Sep 11, 2016

hi guys,

could you please advise on the following ?

Long story short

on the localhost:8900 there is aiohttp server running

Expected behaviour

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"})

Actual behaviour

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

Steps to reproduce

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"}
@asvetlov
Copy link
Member

asvetlov commented Sep 11, 2016

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"}

@nskalis
Copy link
Author

nskalis commented Sep 12, 2016

great. thanks. could you please help me unpack it ?

data is <MultiDictProxy()> for which i didn't find much info

@asvetlov
Copy link
Member

@nskalis
Copy link
Author

nskalis commented Sep 12, 2016

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

@asvetlov
Copy link
Member

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 notifications@github.com
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
#1155 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAVwL31QoLS-1rw3xocHhCjg1g1X5IH-ks5qpSMkgaJpZM4J6GGZ
.

Thanks,
Andrew Svetlov

@nskalis
Copy link
Author

nskalis commented Sep 12, 2016

yes (also changed it to post you are right) :)

@nskalis nskalis closed this as completed Sep 12, 2016
@asvetlov
Copy link
Member

Cool!

On Mon, Sep 12, 2016 at 5:03 PM Nikos Skalis notifications@github.com
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
#1155 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAVwLwRHI3oveQ3Ds5Dv-9tZ-0onLsWlks5qpVtpgaJpZM4J6GGZ
.

Thanks,
Andrew Svetlov

@SaddamBInSyed

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants