Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError('not a valid non-string sequence or mapping object',)

I am using aiohttp get request to download some content from another web api but i am receiving:

exception = TypeError('not a valid non-string sequence or mapping object',)

Following is the data which i am trying to sent.

data = "symbols=LGND-US&exprs=CS_EVENT_TYPE_CD_R(%27%27,%27now%27,%271D%27)"

How to resolve it?

I tried it in 2 ways:

r = yield from aiohttp.get(url, params=data) # and
r = yield from aiohttp.post(url, data=data)

At the same time i am able to fetch data using:

r = requests.get(url, params=data) # and
r = requests.post(url, data=data)

But i need async implementation.

And also suggest me some way if i can use import requests library instead of import aiohttp to make async http request, because in many cases aiohttp post & get request are not working but the same are working for requests.get & post requests.

like image 229
user3540276 Avatar asked Dec 03 '25 09:12

user3540276


1 Answers

The docs use bytes (i.e. the 'b' prefix) for the data argument.

r = await aiohttp.post('http://httpbin.org/post', data=b'data')

Also, the params argument should be a dict or a list of tuples.

like image 58
miles82 Avatar answered Dec 05 '25 01:12

miles82



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!