Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python &引用;ConnectionAbortedError:[WinError 10053]主机中的软件中止了已建立的连接;当我尝试在db中添加图像时_Python_Django - Fatal编程技术网

Python &引用;ConnectionAbortedError:[WinError 10053]主机中的软件中止了已建立的连接;当我尝试在db中添加图像时

Python &引用;ConnectionAbortedError:[WinError 10053]主机中的软件中止了已建立的连接;当我尝试在db中添加图像时,python,django,Python,Django,下面是我的Django models.py文件。 当我尝试将图像上载到数据库时,会出现此错误。它显示无法访问服务器,并在cmd中给出错误信息。当我保存而不上传图像时,效果非常好。有人能帮我解决这个问题吗 # Create your models here. from django.contrib.auth.models import AbstractUser, BaseUserManager from django.db import models from django.contrib.aut

下面是我的Django models.py文件。 当我尝试将图像上载到数据库时,会出现此错误。它显示无法访问服务器,并在cmd中给出错误信息。当我保存而不上传图像时,效果非常好。有人能帮我解决这个问题吗

# Create your models here.
from django.contrib.auth.models import AbstractUser, BaseUserManager
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
import uuid
from django.db.models.signals import post_save, post_delete
from django.utils.timezone import now

class UserManager(BaseUserManager):
    """Define a model manager for User model with no username field."""

    use_in_migrations = True

    def _create_user(self, email,username, first_name, last_name, password, **extra_fields):
        """Create and save a User with the given email and password."""
        if not email:
            raise ValueError('The given email must be set')
        email = self.normalize_email(email)
        user = self.model(email=email,username=username,first_name=first_name,last_name=last_name, **extra_fields)
        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_user(self, email, password=None, **extra_fields):
        """Create and save a regular User with the given email and password."""
        extra_fields.setdefault('is_staff', False)
        extra_fields.setdefault('is_superuser', False)
        return self._create_user(email, password, **extra_fields)

    def create_superuser(self, email, password, **extra_fields):
        """Create and save a SuperUser with the given email and password."""
        extra_fields.setdefault('is_staff', True)
        extra_fields.setdefault('is_superuser', True)

        if extra_fields.get('is_staff') is not True:
            raise ValueError('Superuser must have is_staff=True.')
        if extra_fields.get('is_superuser') is not True:
            raise ValueError('Superuser must have is_superuser=True.')

        return self._create_user(email, password, **extra_fields)


class User(AbstractUser):
    """User model."""

    username = models.CharField(max_length=200, null=True)
    first_name = models.CharField(max_length=200, null=True)
    last_name = models.CharField(max_length=200, null=True)
    email = models.EmailField(('email address'), unique=True)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = UserManager()


class Post(models.Model):
    """post model"""
    id = models.UUIDField(primary_key=True,default=uuid.uuid4,editable=False)
    name = models.CharField(max_length=100,null=False)
    picture = models.ImageField(upload_to='images/', verbose_name='Picture',blank=True)
    file = models.FileField(upload_to='files/',blank=True,verbose_name='File')
    HelpRel = models.TextChoices('HelpRel','Myself Family Friends')
    relation = models.CharField(blank=True, choices=HelpRel.choices,max_length=10)
    description = models.CharField(max_length=300,null=True)
    age = models.PositiveIntegerField(null=True, blank=True)
    posted = models.DateTimeField(default=now)
    user = models.ForeignKey(User,on_delete=models.CASCADE)
Exception occurred during processing of request from ('127.0.0.1', 59879)
Traceback (most recent call last):
  File "C:\Users\bbara\AppData\Local\Programs\Python\Python39\lib\socketserver.py", line 650, in process_request_thread
    self.finish_request(request, client_address)
  File "C:\Users\bbara\AppData\Local\Programs\Python\Python39\lib\socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Users\bbara\AppData\Local\Programs\Python\Python39\lib\socketserver.py", line 720, in __init__
    self.handle()
  File "C:\Users\bbara\Environment\lib\site-packages\django\core\servers\basehttp.py", line 174, in handle
    self.handle_one_request()
  File "C:\Users\bbara\Environment\lib\site-packages\django\core\servers\basehttp.py", line 182, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "C:\Users\bbara\AppData\Local\Programs\Python\Python39\lib\socket.py", line 704, in readinto
    return self._sock.recv_into(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine