Invalid --dateafter crashes with no useful error #15108

Open
opened 2026-02-21 06:46:39 -05:00 by deekerman · 4 comments
Owner

Originally created by @TorC8 on GitHub (Nov 12, 2018).

  • [x ] I've verified and I assure that I'm running youtube-dl 2018.11.07
  • [x ] At least skimmed through the README, most notably the FAQ and BUGS sections
  • [ x] Searched the bugtracker for similar issues including closed ones

What is the purpose of your issue?

  • [x ] Bug report (encountered problems with youtube-dl)

Description:

With a typo in the --dateafter making a nine digit number (in the below example, an extra 1 in the month), youtube-dl crashes without a useful error message for debugging the command. (Edited for clarity)


Minimal example command:

$ youtube-dl -v --dateafter 201811106
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: [u'-v', u'--dateafter', u'201811106']
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/bin/youtube-dl/__main__.py", line 19, in <module>
  File "/usr/local/bin/youtube-dl/youtube_dl/__init__.py", line 472, in main
  File "/usr/local/bin/youtube-dl/youtube_dl/__init__.py", line 220, in _real_main
  File "/usr/local/bin/youtube-dl/youtube_dl/utils.py", line 1330, in __init__
  File "/usr/local/bin/youtube-dl/youtube_dl/utils.py", line 1311, in date_from_str
  File "/usr/lib/python2.7/_strptime.py", line 335, in _strptime
    data_string[found.end():])
ValueError: unconverted data remains: 6

$ youtube-dl --version
2018.11.07

Originally created by @TorC8 on GitHub (Nov 12, 2018). - [x ] I've **verified** and **I assure** that I'm running youtube-dl **2018.11.07** - [x ] At least skimmed through the [README](https://github.com/rg3/youtube-dl/blob/master/README.md), **most notably** the [FAQ](https://github.com/rg3/youtube-dl#faq) and [BUGS](https://github.com/rg3/youtube-dl#bugs) sections - [ x] [Searched](https://github.com/rg3/youtube-dl/search?type=Issues) the bugtracker for similar issues including closed ones ### What is the purpose of your *issue*? - [x ] Bug report (encountered problems with youtube-dl) --- ### Description: With a typo in the --dateafter making a nine digit number (in the below example, an extra 1 in the month), youtube-dl crashes without a useful error message for debugging the command. (Edited for clarity) --- ### Minimal example command: ``` $ youtube-dl -v --dateafter 201811106 [debug] System config: [] [debug] User config: [] [debug] Custom config: [] [debug] Command-line args: [u'-v', u'--dateafter', u'201811106'] Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/usr/local/bin/youtube-dl/__main__.py", line 19, in <module> File "/usr/local/bin/youtube-dl/youtube_dl/__init__.py", line 472, in main File "/usr/local/bin/youtube-dl/youtube_dl/__init__.py", line 220, in _real_main File "/usr/local/bin/youtube-dl/youtube_dl/utils.py", line 1330, in __init__ File "/usr/local/bin/youtube-dl/youtube_dl/utils.py", line 1311, in date_from_str File "/usr/lib/python2.7/_strptime.py", line 335, in _strptime data_string[found.end():]) ValueError: unconverted data remains: 6 ``` $ youtube-dl --version 2018.11.07
Author
Owner

@TorC8 commented on GitHub (Nov 18, 2018):

Ran a couple extra tests. Looks like a short date either works, but may act on a wrong date, or throws a ValueError complaining about an invalid date format. Given what module throws the error, depending on how youtube-dl is allowed to handle errors, this may be an upstream bug.

Fix is probably to add a corrected version of the following to date_from_str in youtube-dl/utils at around line 1811:

if date_str in == re.match(r'^\d{7..}$', date_str)
    report_invalid_date_and_quit
@TorC8 commented on GitHub (Nov 18, 2018): Ran a couple extra tests. Looks like a short date either works, but may act on a wrong date, or throws a ValueError complaining about an invalid date format. Given what module throws the error, depending on how youtube-dl is allowed to handle errors, this may be an upstream bug. Fix is probably to add a corrected version of the following to date_from_str in youtube-dl/utils at around line 1811: ``` if date_str in == re.match(r'^\d{7..}$', date_str) report_invalid_date_and_quit ```
Author
Owner

@TwistingTwists commented on GitHub (Jul 12, 2021):

Is this issue closed?

I faced the same issue today with

youtube-dl --version
 2021.06.06
@TwistingTwists commented on GitHub (Jul 12, 2021): Is this issue closed? I faced the same issue today with ``` youtube-dl --version 2021.06.06 ```
Author
Owner

@TorC8 commented on GitHub (Jul 12, 2021):

Confirmed still extant on 2021.06.06

$ youtube-dl --version
2021.06.06

Invalid date:
$ youtube-dl --dateafter 20120343 "youtube.com/iscoCT"
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "main", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/bin/youtube-dl/main.py", line 19, in
  File "/usr/local/bin/youtube-dl/youtube_dl/init.py", line 475, in main
  File "/usr/local/bin/youtube-dl/youtube_dl/init.py", line 222, in
_real_main
  File "/usr/local/bin/youtube-dl/youtube_dl/utils.py", line 3103, in
init
  File "/usr/local/bin/youtube-dl/youtube_dl/utils.py", line 3084, in
date_from_str
  File "/usr/lib/python2.7/_strptime.py", line 335, in _strptime
    data_string[found.end():])
ValueError: unconverted data remains: 3

Valid date, same invalid video:
$ youtube-dl --dateafter 20120320 "youtube.com/iscoCT"
WARNING: The url doesn't specify the protocol, trying with http
[youtube:tab] iscoCT: Downloading webpage
ERROR: Unable to download webpage: HTTP Error 404: ### Correct
warning/error: invalid video URL

@TorC8 commented on GitHub (Jul 12, 2021): Confirmed still extant on 2021.06.06 $ youtube-dl --version 2021.06.06 -------------------- Invalid date: $ youtube-dl --dateafter 20120343 "youtube.com/iscoCT" Traceback (most recent call last):   File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main     "__main__", fname, loader, pkg_name)   File "/usr/lib/python2.7/runpy.py", line 72, in _run_code     exec code in run_globals   File "/usr/local/bin/youtube-dl/__main__.py", line 19, in <module>   File "/usr/local/bin/youtube-dl/youtube_dl/__init__.py", line 475, in main   File "/usr/local/bin/youtube-dl/youtube_dl/__init__.py", line 222, in _real_main   File "/usr/local/bin/youtube-dl/youtube_dl/utils.py", line 3103, in __init__   File "/usr/local/bin/youtube-dl/youtube_dl/utils.py", line 3084, in date_from_str   File "/usr/lib/python2.7/_strptime.py", line 335, in _strptime     data_string[found.end():]) ValueError: unconverted data remains: 3 --------------------- Valid date, same invalid video: $ youtube-dl --dateafter 20120320 "youtube.com/iscoCT" WARNING: The url doesn't specify the protocol, trying with http [youtube:tab] iscoCT: Downloading webpage ERROR: Unable to download webpage: HTTP Error 404: ### Correct warning/error: invalid video URL
Author
Owner

@TorC8 commented on GitHub (Jul 12, 2021):

Possible sample code. Regex is tested, as far as that goes.

I don't properly understand throwing errors/warnings in yt-dl.

Caveat: The bug I'm seeing actually comes from _strptime in the python 2.7 library. My code won't catch a bad date like 20112233, which will still trigger this bug. It will warn on a valid, but potentially confusing, date like 201111 (Jan 1st 2011 or Nov 11, 2020?) and a valid, single possibility date like 201155. I now believe catching the ValueError is the correct fix, but I'm not up to that now.

## At about line 3063 in utils.py under "def date_from_str()"

if re.match(r'^[0-9]{1,7}$', date_str) :
    write_string(
    'WARNING: date contains insufficient number of digits.  May be parsed incorrectly.'
    % (e, line), sys.stderr)
elif re.match(r'^[0-9]{9,}$', date_str) :
    write_string(
    'ERROR: date contains too many digits."
    % (e, line), sys.stderr)
@TorC8 commented on GitHub (Jul 12, 2021): Possible sample code. Regex is tested, as far as that goes. I don't properly understand throwing errors/warnings in yt-dl. Caveat: The bug I'm seeing actually comes from _strptime in the python 2.7 library. My code won't catch a bad date like 20112233, which will still trigger this bug. It will warn on a valid, but potentially confusing, date like 201111 (Jan 1st 2011 or Nov 11, 2020?) and a valid, single possibility date like 201155. I now believe catching the ValueError is the correct fix, but I'm not up to that now. ```python ## At about line 3063 in utils.py under "def date_from_str()" if re.match(r'^[0-9]{1,7}$', date_str) : write_string( 'WARNING: date contains insufficient number of digits. May be parsed incorrectly.' % (e, line), sys.stderr) elif re.match(r'^[0-9]{9,}$', date_str) : write_string( 'ERROR: date contains too many digits." % (e, line), sys.stderr) ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/youtube-dl#15108
No description provided.