V
V
Viktor Yurchenko2019-02-04 18:52:58
Django
Viktor Yurchenko, 2019-02-04 18:52:58

Error ImportError: uWSGI is not available, how to fix?

I have a destributor.csv file that needs to be unloaded into the database model.
There is a script called import_csv.py
I run it with the following command from the script directory:
../../../manage.py import_csv "/home/webuser/fcprj/media/destributor.csv"
an error is displayed:

Traceback (most recent call last):
  File "../../../manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/webuser/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/webuser/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/webuser/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/webuser/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/home/webuser/fcprj/fcapp/management/commands/import_csv.py", line 31, in handle
    emp.save()
  File "/home/webuser/fcprj/fcapp/models/distributor.py", line 170, in save
    super(Distributor, self).save(*args, **kwargs)
  File "/home/webuser/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 796, in save
    force_update=force_update, update_fields=update_fields)
  File "/home/webuser/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 833, in save_base
    update_fields=update_fields, raw=raw, using=using)
  File "/home/webuser/venv/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 191, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/home/webuser/fcprj/fcapp/models/__init__.py", line 155, in distributor_post_save
    args=[instance.id.hex],
  File "/home/webuser/venv/local/lib/python2.7/site-packages/templated_email/__init__.py", line 67, in send_templated_mail
    headers=headers, **kwargs)
  File "/home/webuser/venv/local/lib/python2.7/site-packages/templated_email/backends/vanilla_django.py", line 180, in send
    e.send(fail_silently)
  File "/home/webuser/venv/local/lib/python2.7/site-packages/django/core/mail/message.py", line 342, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/webuser/venv/local/lib/python2.7/site-packages/django_uwsgi/mail.py", line 11, in send_messages
    if self._send(email_message):
  File "/home/webuser/venv/local/lib/python2.7/site-packages/django_uwsgi/mail.py", line 16, in _send
    from .task import send_mail
  File "/home/webuser/venv/local/lib/python2.7/site-packages/django_uwsgi/task.py", line 4, in <module>
    from .decorators import spool
  File "/home/webuser/venv/local/lib/python2.7/site-packages/django_uwsgi/decorators.py", line 17, in <module>
    raise ImportError("uWSGI is not available")
ImportError: uWSGI is not available

Script code:
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand, CommandError
from fcapp.models import Distributor
import csv

class Command(BaseCommand):

    def add_arguments(self, parser):
        parser.add_argument('csv_file', nargs='+', type=str)

    def handle(self, *args, **options):
        for csv_file in options['csv_file']:
            dataReader = csv.reader(open(csv_file), delimiter=';', quotechar='"')
            for row in dataReader:
                emp = Distributor()
                emp.name = row[0]
                emp.full_name = row[0]
                #print(row[0])
                emp.address = row[1]
                emp.phone = '{0} {1}'.format(row[2],row[3])
                emp.email = row[4]
                emp.site = row[5]
                #emp.api_key= 'uniqkey'
                emp.language = 'ru'
                emp.api_key_status='inactive'
                emp.api_key_end_date_0 = '12.12.2016'
                emp.api_key_end_date_1 = '14:12:05'
                emp.api_requests_available = 0
                emp.turnover =  0
                emp.coef = 1.40
                emp.save()
                print(emp.name + 'save')
                #self.stdout.write(
                #    'Created distributor {}'.format(emp.name)
                #)

I found some answers, but still something does not reach how to fix this error
https://stackoverflow.com/questions/18417823/how-d...
https://stackoverflow.com/questions/8241680/django...
As I understand it, I need to register something in the virtual environment, but I can’t figure out what and where.
The problem occurs in this line:
emp.save()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alternativshik, 2019-02-04
@alternativshik

Judging by the trace, it crashes when saving, at the same time, it tries to send an error message to the mail, and then it crashes further due to the lack of uwsgi, which you can install pip install uwsgi or fix sending mail in settings, and then see what it is crashes on save.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question