Dateutil.parser parsing the time problem, unable to get the correct time

Using celery to execute tasks asynchronously, the time of the text needs to be parsed in the task. Normally, an error will be reported in the try process during parsing, and then the correct time will be obtained by executing the content of except    But the local running process is normal, but the online is wrong, the content under except is not executed online, and the wrong time is obtained.

# environment
python3.8
ubuntu14
python-dateutil = ">=2.5.2"

# imported package
from dateutil.parser import parse
# parsing time
def parse_datetime(msg):
    try:
        dt = parse(msg, fuzzy=True)
        print("dt: ", dt)
        return dt.strftime('%Y-%m-%d %H:%M:%s')
    except Exception as e:
        print(e)
        ...
        return time_.strftime('%Y-%m-%d %H:%M:%S')
# result of execution
time_ = parse_datetime(msg="下午5点53")
# dt print result
dt :2053-05-25 00:00:00     # type:<class 'datetime.datetime'>

# The result is normally an error when formatting, but the online environment does not report an error, and the result is directly obtained

The result of local parsing is normal:local run result

The online running result is wrong, the code content below the except is not executed, and the wrong result is directly obtained:Online Environmental Results

The result of the local python environment test is also wrong:local python

Back to Top