smtp - Export django settings to my python file -


i trying make logparser.py in django project parses data coming different servers.

and on running command on terminal :

$ python logparser.py

this error coming :

traceback (most recent call last):   file "logparser.py", line 13, in <module>     smtp_conf = settings.smtp_conf   file "/home/arya/.virtualenv/devel/.virtualenvs/hu/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__     self._setup(name)   file "/home/arya/.virtualenv/devel/.virtualenvs/hu/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in _setup     self._wrapped = settings(settings_module)   file "/home/arya/.virtualenv/devel/.virtualenvs/hu/local/lib/python2.7/site-packages/django/conf/__init__.py", line 134, in __init__     raise importerror("could not import settings '%s' (is on sys.path?): %s" % (self.settings_module, e)) importerror: not import settings 'hma.settings' (is on sys.path?): no module named hma.settings 

my logparser.py contains:

import re import os import fnmatch import gzip import bz2 collections import defaultdict  django.core.mail import send_mail django.core.mail.backends import smtp  import smtplib email.mime.text import mimetext os.environ.setdefault("django_settings_module", "hma.settings") django.conf import settings smtp_conf = settings.smtp_conf  def send_email(self,fromaddress,toaddresses,content,subject):     smtp_server = smtp_conf["server"]     smtp_username = smtp_conf["username"]     smtp_password = smtp_conf["password"]     smtp_port = smtp_conf["port"]       msg = mimetext(content, 'html', _charset='utf-8')      msg['subject'] ='alert message bad , internal server error'      msg['from'] = fromaddress     msg['to'] = toaddresses     server = smtplib.smtp(smtp_server,smtp_port)     server.starttls()     server.login(smtp_username,smtp_password)     server.send_mail(fromaddress,toaddresses,msg.as_string())     server.quit()     return true 

i know doing wrong command [python manage.py], need run this. solution exporting django settings separate python file??

well, exact usecase why django provided ability create custom commands. can use features of django, in script, script running inside django container. here documentation https://docs.djangoproject.com/en/dev/howto/custom-management-commands/.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -