jwt_tool
jwt_tool copied to clipboard
ValueError: year 53831 is out of range
Traceback (most recent call last):
File "/opt/jwt_tool/jwt_tool.py", line 2028, in <module>
rejigToken(headDict, paylDict, sig)
File "/opt/jwt_tool/jwt_tool.py", line 1291, in rejigToken
comparestamps, expiredtoken = dissectPayl(paylDict)
File "/opt/jwt_tool/jwt_tool.py", line 1185, in dissectPayl
timestamp = datetime.fromtimestamp(int(paylDict[claim]))
ValueError: year 53831 is out of range
I was able to resolve this issue by using the Arrow library and editing a few lines in jwt_tool.py. If anyone is interested in the solution, let me know.
Sorry for the slow response. What was in your token to cause this error? Can you supply an example? If it's going to affect others I'll happily patch it. You can submit a PR if you have a fix.
So I encountered the same or similar issue, it looks to be when the timestamps issued are in milliseconds vs seconds. Datetime wants the timestamp value in seconds.
In order to get it working with minimal effort I just caught the error if it happened and retried dividing the claim by 1000, not the most elegant though.
For testing 1639007079948 was the timestamp from my claim.
I'd think testcases that involve tampering with the timestamp would also fail server side though as well unless it was accounted for or changed back to milliseconds.
I have run into this as well. The solution spacesedge suggested works for reading JWTs but clearly it's not enough if you need to tamper.
Any solution for this?
I was able to resolve this issue by using the Arrow library and editing a few lines in jwt_tool.py. If anyone is interested in the solution, let me know.
yes please.
I fixed it by catching the exception and dividing the value by 1000. Replace line 1185 with the following code:
try:
timestamp = datetime.fromtimestamp(int(paylDict[claim]))
except ValueError:
ts = paylDict[claim] / 1000
timestamp = datetime.fromtimestamp(ts)