~stacylo


#160 Feb 29 Error -- ValueError: day is out of range for month 11 months ago

Comment by ~stacylo on ~sschwarzer/ftputil

Yeah okay, I think the problem has been resolved.

ftp_host.synchronize_times() does not work for me. It threw the same error.

So I did ftp_host.set_time_shift(time_shift=28800) before ftp_host.listdir(folder_path), and it worked.

It is also a good suggestion to set a high shift because all I need is the list of file names.

Thank you!!!

#160 Feb 29 Error -- ValueError: day is out of range for month 11 months ago

Comment by ~stacylo on ~sschwarzer/ftputil

Can you print the whole problematic line before it gets parsed (or tried to be parsed ;-) )?

Yes, it is: drwxr-xr-x 1 ftp ftp 0 Feb 29 17:31 .

#160 Feb 29 Error -- ValueError: day is out of range for month 11 months ago

Comment by ~stacylo on ~sschwarzer/ftputil

For the time zone, my local machine is UTC+8. The FTP server should be UTC+8 as well, but I am not sure.

The values of the arguments of parse_unix_time are

  • month_abbreviation='Feb'
  • day='29'
  • year_or_time='17:12'
  • time_shift=0.0
  • with_precision=True

#160 Feb 29 Error -- ValueError: day is out of range for month 11 months ago

Comment by ~stacylo on ~sschwarzer/ftputil

Hi Stefan,

I ran it sometime in the morning between 10:30 and 11:00, Feb 29, 2024. And yes, the time should not matter. I believe the error is going to occur for the whole day Feb 29, 2024.

Below is the traceback for the error so you can see which line. (Sorry about the format. Do you know how I can keep the correct line breaks in the markdown?)


Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 210, in _datetime
    return datetime.datetime(
           ^^^^^^^^^^^^^^^^^^
ValueError: day is out of range for month

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 801, in __call_with_parser_retry
    result = method(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 768, in _real_stat
    lstat_result = self._real_lstat(path, _exception_for_missing_path)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 729, in _real_lstat
    for stat_result in self._stat_results_from_dir(dirname):
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 636, in _stat_results_from_dir
    stat_result = self._parser.parse_line(line, self._host.time_shift())
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 472, in parse_line
    st_mtime, st_mtime_precision = self.parse_unix_time(
                                   ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 308, in parse_unix_time
    server_utc_datetime = self._datetime(
                          ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 218, in _datetime
    raise ftputil.error.ParserError(
ftputil.error.ParserError: invalid datetime '2023-02-29 17:02:00'
Debugging info: ftputil 5.1.0, Python 3.11.8 (linux)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 549, in parse_line
    st_size = int(dir_or_size)
              ^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'ftp'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/project/src/main.py", line 49, in <module>
    main()
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/project/src/main.py", line 36, in main
    is_success = import_orders(sap_environment=sap_environment)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/project/src/functions/import_orders.py", line 429, in import_orders
    is_success_1 = process_folder(sap_grpc_client=sap_grpc_client, ftp_host=ftp_host, folder_dict=folder_dict)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/project/src/functions/import_orders.py", line 372, in process_folder
    object_name_list = ftp_host.listdir(folder_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/host.py", line 988, in listdir
    items = self._stat._listdir(path)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 825, in _listdir
    return self.__call_with_parser_retry(self._real_listdir, path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 801, in __call_with_parser_retry
    result = method(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 680, in _real_listdir
    if not self._path.isdir(path):
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/path.py", line 154, in isdir
    return self._is_file_system_entity(path, "dir")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/path.py", line 132, in _is_file_system_entity
    stat_result = self._host.stat(path, _exception_for_missing_path=False)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/host.py", line 1024, in stat
    return self._stat._stat(path, _exception_for_missing_path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 845, in _stat
    return self.__call_with_parser_retry(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 801, in __call_with_parser_retry
    result = method(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 768, in _real_stat
    lstat_result = self._real_lstat(path, _exception_for_missing_path)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 719, in _real_lstat
    if not self._path.isdir(dirname) and not _exception_for_missing_path:
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/path.py", line 154, in isdir
    return self._is_file_system_entity(path, "dir")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/path.py", line 132, in _is_file_system_entity
    stat_result = self._host.stat(path, _exception_for_missing_path=False)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/host.py", line 1024, in stat
    return self._stat._stat(path, _exception_for_missing_path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 845, in _stat
    return self.__call_with_parser_retry(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 811, in __call_with_parser_retry
    return method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 768, in _real_stat
    lstat_result = self._real_lstat(path, _exception_for_missing_path)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 729, in _real_lstat
    for stat_result in self._stat_results_from_dir(dirname):
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 636, in _stat_results_from_dir
    stat_result = self._parser.parse_line(line, self._host.time_shift())
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 551, in parse_line
    raise ftputil.error.ParserError("invalid size {}".format(dir_or_size))
ftputil.error.ParserError: invalid size ftp
Debugging info: ftputil 5.1.0, Python 3.11.8 (linux)

#160 Feb 29 Error -- ValueError: day is out of range for month 11 months ago

on ~sschwarzer/ftputil

Hi ~stacylo, thanks for the report!

Do you have the line from the directory listing where the error occured? You can add a

print("===", line)

at line 472. You can obscure the file name if it's necessary for privacy reasons.

Also, even if it probably doesn't matter, at which time (roughly) did you run the listdir call?

#160 Feb 29 Error -- ValueError: day is out of range for month 11 months ago

Ticket created by ~stacylo on ~sschwarzer/ftputil

Hello,

I am on ftputil 5.1.0, Python 3.11.8 (linux)

Today is a special date, Feb 29, 2024. I am at timezone UTC+8.

I am getting an error in my code

object_name_list = ftp_host.listdir(folder_path)

Error message is:

> Traceback (most recent call last):
>  File "/usr/local/lib/python3.11/site-packages/ftputil/stat.py", line 210, in _datetime
>    return datetime.datetime(
>           ^^^^^^^^^^^^^^^^^^
> ValueError: day is out of range for month

After digging into it I can tell that the error came from Line 308 to Line 311:

>        server_utc_datetime = self._datetime(
>            server_year, month, day, hour, minute, 0
>        ) - datetime.timedelta(seconds=time_shift)
>        st_mtime = server_utc_datetime.timestamp()

When it tried to subtract one year from the current date, an exception happened as Feb 29, 2023 is not a valid date.

I believe the error will go away tomorrow, but it would be great if it could be fixed before the next Feb 29 :)

Thank you, Stacy