2

I have whittled a much-larger Flask app down to the essentials in order to try to figure out why dateparser (0.7.6 and also 1.0.0) is not working in Flask (Flask 1.1.2, Werkzeug 1.0.1) under Python 3.8.5 in Windows 10.

run.py

from mytest import app as _application

def application(environ, start_response):
    return _application(environ, start_response)

if __name__ == '__main__':
    from werkzeug.serving import run_simple
    run_simple('localhost', 5003, application, use_reloader=True, use_debugger=True, threaded=True, use_evalex=True)

mytest.py

import os, dateparser, time
from flask import Flask

app = Flask(__name__)
# os.environ['TZ'] = 'UTC'

@app.route('/')
def date_test():
    parsed = dateparser.parse('01/13/2021')
    return 'Date parse results are: {}'.format(parsed)

This app runs fine - going to http://127.0.0.1:5003 produces "Date parse results are: 2021-01-13 00:00:00"

However, if I uncomment line 5 in mytest.py (os.environ['TZ'] = 'UTC'), dateparser suddenly stops working and the URL returns "Date parse results are: None"

There are some ways I've found to mitigate it:

  1. In run.py, move the from mytest import app as _application line into the application function
  2. In mytest.py, move the os.environ['TZ']... line into the date_test function

but I don't really understand why the problem is happening in the first place, or why either of those two "solutions" actually solves the problem.

What am I missing?

davidism
  • 121,510
  • 29
  • 395
  • 339
David White
  • 1,763
  • 2
  • 16
  • 27

0 Answers0