ihabunek / toot

toot - Mastodon CLI & TUI
GNU General Public License v3.0
1.16k stars 111 forks source link

toot fails to get messages with ValueError (time format mismatch) #397

Open smeagolthellama opened 1 year ago

smeagolthellama commented 1 year ago

I just logged in for the first time via toot (to the server at fe.disroot.org, which is running Mastodon 2.7.2 (compatible; Akkoma 3.8.0-0-gb86b3a9-develop) according to toot instance, in case it's a server-specific thing), and both toot tui and toot timeline fail with an error similar to the one seen at #114, except referring to what appears to be the unix epoch.

Actually, now toot timeline only shows the error when I say yes to the first "Continue?" dialogue. I've attached the error from timeline.

toot version: 0.34.1-1 from the devuan repos python version: 3.11.2 operating system: devuan (daedalus) linux (think debian w/o systemd)

Traceback (most recent call last):
  File "/usr/bin/toot", line 33, in <module>
    sys.exit(load_entry_point('toot==0.34.1', 'console_scripts', 'toot')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/toot/console.py", line 694, in main
    run_command(app, user, command_name, args)
  File "/usr/lib/python3/dist-packages/toot/console.py", line 675, in run_command
    return fn(app, user, parsed_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/toot/commands.py", line 56, in timeline
    print_timeline(items)
  File "/usr/lib/python3/dist-packages/toot/output.py", line 314, in print_timeline
    print_status(item, width)
  File "/usr/lib/python3/dist-packages/toot/output.py", line 236, in print_status
    time = parse_datetime(status['created_at'])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/toot/tui/utils.py", line 24, in parse_datetime
    dttm = datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=timezone.utc)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '1970-01-01T00:00:00Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
danschwarz commented 1 year ago

Weird. So the server is sending a "created_at" time stamp of 0. That is weird, but probably shouldn't cause toot to crash. I'll look at it if I can get a server login there.

smeagolthellama commented 1 year ago

By the way, it seems to have resolved itself after a day or two. My guess is that it sent a nulled post as the terminator for the list of posts it sends (although I don't know why it would have sent less than a page or two worth of posts, as I've had this account for a couple months at this point). Also, the server has had an update since then, so that also might have solved the issue.

danschwarz commented 1 year ago

Thanks for the update. So if I test now, it won't exhibit the behavior. OTOH, toot should not crash in response to invalid input of this kind. So I can simulate the problem by setting the "created at" timestamp to 0 / null and see what happens.