Home > Blockchain >  Python requests literal vs computed
Python requests literal vs computed

Time:10-30

Unbelieveable (or totally stupid)

from_ts=int(thirty_secs_ago - delay)
till_ts=int(last_poll - delay)
payloadjson = { "tokens": tokens ,"timestamp": { "start": from_ts, "end": till_ts } }
r = requests.request('GET', api_url, headers=headers, json=payloadjson)

Returns 0 events between the two timestamps

from_ts=1666729135
till_ts=1666729165
payloadjson = { "tokens": tokens ,"timestamp": { "start": from_ts, "end": till_ts } }
r = requests.request('GET', api_url, headers=headers, json=payloadjson)

returns the events I want.

But when I dump payloadjson from computed attempt, and I run the request from a shell/curl/postman, it returns values, and is indiscernable from the literals in appearance

What silly error am I doing?

CodePudding user response:

Solution:

When messing with recent timestamps, always be patient.

The data was not yet ready on server when running the computed value.

The literals are precomputed, manually put into the script, which gives the server sufficient time to receive and process the data.

So it's not a data format error, it's a data availability problem. Increasing the delay solves this (and we have to live with the delay)

  • Related