0

I use a python library(aiohttp) to get the response form post request. Can I get sequential result? How to...?

import aiohttp
import asyncio
import base64
import json
from tqdm import tqdm
import time



f = open('C:\\Users\\fangchao\\Pictures\\face1.jpg', 'rb').read()
image_64_encode = base64.b64encode(f).decode("utf-8")
files = {"target1": {"photoFormat": "image/jpeg", "photoData": image_64_encode, "faceLocator": None}, "target2": {"photoFormat": "image/jpeg", "photoData": image_64_encode, "faceLocator": None}, "threshold": 0}
url = "http://10.122.100.64:8080/v4/query/verify"


async def fetch(session, url):
    async with session.post(url, data=json.dumps(files)) as response:
        return await response.text()

async def main(url):
    async with aiohttp.ClientSession() as session:
        html = await fetch(session, url)
        text = json.loads(html)
        print(text["score"])


a = time.time()
loop = asyncio.get_event_loop()
tasks = [main(url) for i in range(1000)]
loop.run_until_complete(asyncio.wait(tasks))
print(time.time() - a)

Only can i get a score form response, so I want to know what two images are if I use many post to get response. So I need a sequential result

  • If you mean print them in order.... you cant like that. Because the execution is not guaranteed. You can `gather` the results and order them for example. Would that be ok? – Netwave Apr 29 '19 at 07:15
  • what's your definition of in order, can you give some examples? – Zik Apr 29 '19 at 08:04
  • I means I put image named 1,2; 3,4 ; 5,6 to post, then I get scores look like a , b, c. The a is 1,2's socre ,b is 3,4's , c is 5,6's – fangchao Apr 29 '19 at 08:53

0 Answers0