-
-
Save sboily/6fe5c656130dc703b7e86a8d2a863ddb to your computer and use it in GitHub Desktop.
List call from rtpengine python asyncio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import aiohttp | |
import asyncio | |
import bencodepy | |
import random | |
async def main(): | |
headers = {'content-type': 'application/x-rtpengine-ng'} | |
async with aiohttp.ClientSession(headers=headers) as session: | |
cookie = f"0_{random.randint(1000, 9999)}_1" | |
bdata = bencodepy.encode({'command': 'list'}).decode('utf-8') | |
data = f"{cookie} {bdata}" | |
async with session.post('http://xxx.xxx.xxx.xxx:xxx/ng', data=data) as response: | |
result = await response.text() | |
result = result.split(" ", 1) | |
r = bencodepy.decode(result[1]) | |
print(r) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your reply!
When I do request to the localhost (I ran this script on rtpengine instance):
at line 17, I got this
print(result):
['0_5679_1',__ 'd5:callsl36:d38851c7-cf98-4cf8-9e6f-d0ab13877a7ee6:result2:oke']
print(type(result)):
<class 'list'>
print(result[1]):
d5:callsl36:d38851c7-cf98-4cf8-9e6f-d0ab13877a7ee6:result2:oke
print(type(result[1])):
<class 'str'>
and then that error that was posted above at the command bencodepy.decode(result[1])
I hope it could be useful for someone who will use your script.