#๐Ÿ”’ why do i get this error ValueError: invalid literal for int() with base 10: '2023-08-11T05:30:09+0

34 messages ยท Page 1 of 1 (latest)

pallid haven
#

i have this converted_time = datetime.fromtimestamp(int(json_data['items'][0]['date_published'])).strftime("%Y/%m/%d") which converts 2023-08-11T05:30:09+000 to 2023/08/11 but it gives me an error ```Traceback (most recent call last):
File "C:\Users\pinhe\discordbot test\for test usage\op.py", line 76, in <module>
asyncio.run(gog_data('https://www.gog.com/en/game/fallout_4_game_of_the_year_edition'))
File "C:\Users\pinhe\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Users\pinhe\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\pinhe\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 664, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\pinhe\discordbot test\for test usage\op.py", line 70, in gog_data
converted_time = datetime.fromtimestamp(int(json_data['items'][0]['date_published'])).strftime("%Y/%m/%d")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '2023-08-11T05:30:09+0000'

void cliffBOT
#

@pallid haven

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tranquil hearth
weak merlin
#

I think it might work if you move a closing parenthesis to the end. (But not tested)

pallid haven
#

okay.

#

i dont understand what you mean

weak merlin
#

Right.

#

Ill need my computer for this. ๐Ÿ˜…

pallid haven
#

ok ๐Ÿคฃ

pallid haven
#

But then it gives me an error saying that type 'str' cannot be int

tranquil hearth
#

2023-08-11T05:30:09+000
The time zone format is not correct
it should be
2023-08-11T05:30:09+00:00
or 2023-08-11T05:30:09+00

format 'ยฑ[hh]:[mm]', 'ยฑ[hh][mm]', or 'ยฑ[hh]'

#

Then you can use

to extract

sharp fable
pallid haven
#

Ok

#
  File "C:\Users\pinhe\discordbot test\for test usage\op.py", line 76, in <module>
    asyncio.run(gog_data('https://www.gog.com/en/game/fallout_4_game_of_the_year_edition'))
  File "C:\Users\pinhe\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\pinhe\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\pinhe\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 664, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\pinhe\discordbot test\for test usage\op.py", line 70, in gog_data
    converted_time = datetime.fromtimestamp(json_data['items'][0]['date_published']).strftime("%Y/%m/%d")
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'str' object cannot be interpreted as an integer```
#

this is the full error

pallid haven
#

so i have to somehow have to be able to change 2023-08-11T05:30:09+000 to 2023/08/11

sharp fable
pallid haven
#

Ok

weak merlin
#

That will have a str doesnt have strftime I'm guessing.
It's a bit hacky but:

#

!e

from datetime import datetime

strtime = "2023-08-11T05:30:09+000"
print("in",strtime)
strtime = strtime.split("T")[0]

x = datetime.strptime(strtime, "%Y-%m-%d").strftime("%Y/%m/%d")
print("out",x)
void cliffBOT
#

@weak merlin :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | in 2023-08-11T05:30:09+000
002 | out 2023/08/11
pallid haven
#

okay thx

#

it worked

#

?solved

sharp fable
pallid haven
#

oh

#

oops

#

๐Ÿคฃ

#

!solved

void cliffBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.