vfilimonov/pydatastream

Bug: InvalidToken exception raised from request_many

Closed this issue · 4 comments

We're observing occurences of InvalidToken exceptions when calling the request_many function (see screenshot below).

There are two underlying issues that need to be addressed in _token_is_expired property:

  1. Datastream's TokenExpiry is a UTC datetime, but is compared with the local datetime pd.Timestamp('now'). Suggestion for line 195: if self._token['TokenExpiry'] < pd.Timestamp.utcnow() - pd.Timedelta(minutes=15):.
  2. Datastream returns tokens that are supposedly valid for 24 hours, but in practice does not seem to honour that commitment. Therefore, I think it would be safer to also say that a token expires after 1 hour in addition to (1). (The reason we believe this is necessary is because we're in UTC+2, which means that pydatastream should refresh the token 2 hours and 15 minutes before the 24 hour period is over and even so we encounter InvalidTokens.)

Screenshot:
image

Thanks for the report, @lsorber!
It makes sense, I will have a look.

Quick fix is in master. As a compromise, I set the max lifetime of a token to 6 hours. Would you agree, @lsorber ? If there're no questions I'd push the new version to pypi on Friday.

Initially I thought of automatically renewing token if "Token has expired" message is received. But on the other hand, if this happens then something is wrong on the server side or the logic of token validation has changed. So I think, it is better to explicitly address this issue rather than swallow it.

LGTM, thank you!

PyDatastream 0.6.4 with the fix is in the pypi