Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.2K
Views
PytzUsageWarning: The zone attribute is specific to pytz's interface; please migrate to a new time zone provider

I am writing a simple function that sends messages based on a schedule using AsyncIOScheduler.

scheduler = AsyncIOScheduler()
scheduler.add_job(job, "cron", day_of_week="mon-fri", hour = "16")
scheduler.start()

It seems to work, but I always get the following message:

PytzUsageWarning: The zone attribute is specific to pytz's interface; please migrate to a new time zone provider. For more details on how to do so, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
PytzUsageWarning: The localize method is no longer necessary, as this time zone supports the fold attribute (PEP 495)

I am not familiar with time in python at all, so I am not really sure what this message is asking me to do. I visited the link provided in the message, but the explanation there is too complicated for me. As I understand, I have to migrate to using PEP495, but how exactly can I do just that?

over 4 years ago · Santiago Trujillo
4 answers
Answer question

0

To set a PIP495 compatible timezone in APScheduler, set a parameter when instantiating the scheduler:

scheduler = AsyncIOScheduler(timezone="Europe/Berlin")
scheduler.add_job(job, "cron", day_of_week="mon-fri", hour = "16")
scheduler.start()

With flask-APScheduler (version 1.12.2), add the timezone to the configuration class:

"""Basic Flask Example from flask-apscheduler examples, file jobs.py"""
from flask import Flask
from flask_apscheduler import APScheduler


class Config:
    """App configuration."""
    JOBS = [
        {
            "id": "job1",
            "func": "jobs:job1",
            "args": (1, 2),
            "trigger": "interval",
            "seconds": 10,
        }
    ]
    SCHEDULER_API_ENABLED = True
    SCHEDULER_TIMEZONE = "Europe/Berlin"  # <========== add here


def job1(var_one, var_two):
    print(str(var_one) + " " + str(var_two))


if __name__ == "__main__":
    app = Flask(__name__)
    app.config.from_object(Config())

    scheduler = APScheduler()
    scheduler.init_app(app)
    scheduler.start()

    app.run()
over 4 years ago · Santiago Trujillo Report

0

For now, you can't effectively suppress these warnings, because the problem comes from apscheduler itself.

In your particular case warning comes from here

if obj.zone == 'local':

The problem is pytz is considered deprecated in favor of zoneinfo module and its backports. So even if you set directly timezone argument as suggested before, you'll probably face the same warning from some other places until apsheduler would fix pytz usage for modern Python version.

But still, actually, there is something that you could do, but I'm not sure if such kind of fixes is acceptable for you.

PytzUsageWarning comes from pytz_deprecation_shim package which is the dependency of tzlocal. tzlocal is deeply integrated with pytz. As apscheduler has relatively relax dependency for tzlocal, you can install pretty old version of one, that hasn't such warning, but still acceptable for apsscheduler itself.

pip install tzlocal==2.1

But, please, pay attention it could break other project dependencies, so be careful.

over 4 years ago · Santiago Trujillo Report

0

I was getting the same warning message because of the zone.

What I did was:

import tzlocal

scheduler = AsyncIOScheduler(timezone=str(tzlocal.get_localzone()))

With that local timezone I'm not getting the warning message anymore and it's running correctly.

over 4 years ago · Santiago Trujillo Report

0

I just changed to

if __name__ == '__main__':
scheduler = BlockingScheduler(timezone=pytz.timezone('Asia/Ho_Chi_Minh'))
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!