Forums

Tasks custom management command problem

Hi,

I like to schedule a management command like this::

python3.8 /home/my_username/My_directory/manage.py emta_leader_monthly

The script:

emta_leader_monthly.py

from django.core.management.base import BaseCommand
from django.core.mail import send_mail

class Command(BaseCommand):

    help = "EMTA havi vezetői email"

    def handle(self, *args, **kwargs):

        send_mail(
            'Hello',
            'Here is the message.',
            'xy@m.com',
            ['someone@gmail.com'],
            fail_silently=False,
         )
         print('Sent')

The file above placed here:

My_directory/app_dir/management/commands/emta_leader_monthly.py

If I run python3 manage.py emta_leader_monthly from the bash console, it works fine. If I add a task I wrote above it gives me this error but I don't use import-export modul here:

Traceback (most recent call last):
File "/home/ruszakmiklos/MPSA/manage.py", line 22, in <module>
main()
File "/home/ruszakmiklos/MPSA/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/lib/python3.8/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/usr/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/usr/lib/python3.8/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'import_export'

2022-04-23 12:03:13 -- Completed task, took 7.04 seconds, return code was 1.

UPDATE: I commented out the import-export module. After that step it started to list all the modules I added and works fine like django_otp.

What happens when you run

python3.8 /home/my_username/My_directory/manage.py emta_leader_monthly

in a console?