I am trying to convert an epoch timestamp to datetime.
I have tried using datetime.fromtimestamp but it gives me an invalid argument error.
Here is my code:
def get_last_login(name):
url = f"https://api.hypixel.net/player?key={API_KEY}&name={name}"
res = requests.get(url)
data = res.json()
if data["player"] is None:
return None
lastlogouttime = (data["player"]["lastLogout"])
timedate = datetime.fromtimestamp(lastlogouttime)
return format(timedate)
lastlogouttime returns an epoch timestamp from the hypixel api.
Edit: Full traceback:
Ignoring exception in command lastlogin:
Traceback (most recent call last):
File "C:\Users\Deagan\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Deagan\Desktop\hybot\bot.py", line 46, in lastlogin
lastlogin = hypixelcustomwrapper.get_last_login(name)
File "C:\Users\Deagan\Desktop\hybot\hypixelcustomwrapper.py", line 74, in get_last_login
timedate = datetime.fromtimestamp(lastlogouttime)
OSError: [Errno 22] Invalid argument
Import statement:
from datetime import datetime, timezone
What it gets from the api:
"lastLogout":1589588947970"
What it should return:
1589588947970