Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.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 django中的自定义用户身份验证和oauth2面临问题_Python_Django - Fatal编程技术网

Python django中的自定义用户身份验证和oauth2面临问题

Python django中的自定义用户身份验证和oauth2面临问题,python,django,Python,Django,我正在制作一个具有受保护API的应用程序,只有经过身份验证的用户才能访问它。为了利用django强大的身份验证功能,我决定用一些额外的字段和自定义字段扩展它的用户模型。 我通过扩展AbstractUser模型来使用自定义用户模型。但在请求oauth2令牌时面临以下问题。 下面是我的代码: class MyUser(AbstractUser): """Extended version of Django User Model""" is_email_verified = model

我正在制作一个具有受保护API的应用程序,只有经过身份验证的用户才能访问它。为了利用django强大的身份验证功能,我决定用一些额外的字段和自定义字段扩展它的用户模型。 我通过扩展AbstractUser模型来使用自定义用户模型。但在请求oauth2令牌时面临以下问题。 下面是我的代码:

class MyUser(AbstractUser):
    """Extended version of Django User Model"""
    is_email_verified = models.BooleanField(
        verbose_name="Email Verified?",
        default=False, choices=T_N_F_CHOICES, auto_created=True,
        help_text="This flag indicates if the email address is authentic and validated"
    )
    mobile = PhoneNumberField(
        verbose_name="Phone Number", blank=True, null=True, unique=True
    )
    is_mobile_verified = models.BooleanField(
        verbose_name="Mobile Verified?",
        default=False, choices=T_N_F_CHOICES, auto_created=True,
        help_text="This flag indicates if the mobile number is authentic and validated"
    )
    profile_pic = models.ImageField(
        verbose_name="Profile Picture",
        upload_to=settings.UPLOAD_DIR,
        height_field=None,
        width_field=None,
        max_length=None,
        blank=True,
        null=True
    )

    USERNAME_FIELD = "email"
    REQUIRED_FIELDS = ['mobile']

    objects = CustomUserManager()

    def __str__(self):
        return self.email

    class Meta:
        managed = True
        db_table = "MyUser"
        verbose_name = "MyUser"
        verbose_name_plural = "MyUsers"
设置.py

...
AUTH_USER_MODEL = 'users.AlphaslateUser'
CORS_ORIGIN_ALLOW_ALL = True
...
INSTALLED_APPS = [
    ...
    'oauth2_provider',
    'corsheaders',
    'countries_plus',
    'rest_framework',
    'users',
]
...
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
    ]
}
...
AUTHENTICATION_BACKENDS = (
    'oauth2_provider.backends.OAuth2Backend',
    'django.contrib.auth.backends.ModelBackend'
)
...
MIDDLEWARE = [
    ...
    'corsheaders.middleware.CorsMiddleware',
    'oauth2_provider.middleware.OAuth2TokenMiddleware',
]
当我从令牌url请求令牌时,我面临以下错误

Internal Server Error: /o/token/
Traceback (most recent call last):
...
packages/oauthlib/common.py", line 436, in __getattr__
    raise AttributeError(name)
AttributeError: get_full_path

如果有人知道如何解决。非常感谢。

这是outhlib代码版本1.3.0中的问题 请看我从哪里知道的。我将版本降级为1.2.0,问题得到解决