1

I'm calling the following JSON-EndPoint in order to retrieve the following value of reference_number.

Using a normal for loop for 3 requests, I've been able to receive a new token per each request as below:

import httpx


for _ in range(3):
    r = httpx.get(
        'https://zenpay.zenithpayments.com.au/CyberSource/getsignedobject?programId=2&siteId=2')
    print(r.json()['signedObject']['reference_number'])

Output:

P2S2M1R20210307004644
P2S2M1R20210307004645
P2S2M1R20210307004646

Now, I'm trying to send an async requests where each request using it's own session but i keep getting the same value for all requests sent in same time.

import trio
import httpx


async def main():

    async with trio.open_nursery() as nurse:

        async def call():
            async with httpx.AsyncClient(timeout=None) as client:
                r = await client.get('https://zenpay.zenithpayments.com.au/CyberSource/getsignedobject?programId=2&siteId=2')
                print(r.json()['signedObject']['reference_number'])

        for _ in range(3):
            nurse.start_soon(call)


if __name__ == "__main__":
    trio.run(main)

Output:

P2S2M1R20210307004912
P2S2M1R20210307004912
P2S2M1R20210307004912

Note: I know that the value is incremented by 1 on each request but i can't use this solution as this value needs to be generated by the BackEnd API in order to authenticate using it later.

On the other side, i don't think it's related to be controlled according to the origin IP address as the API already generate the token once you hit individually.

I can set a time delay between the requests but that's will slow down my entire operation.

I've verified that each client is represent it's own which means the underlying socket identifier is different on each request.

print(client, r.json()['signedObject']['reference_number'])

Output:

<httpx.AsyncClient object at 0x000001EF7815BF40> P2S2M1R20210307005512
<httpx.AsyncClient object at 0x000001EF78185250> P2S2M1R20210307005512
<httpx.AsyncClient object at 0x000001EF7817C670> P2S2M1R20210307005512

is there a clue here ? as I tried even to play with the HTTP Transport but i couldn't figure out what to do with it!

0 Answers0