2017-05-27 68 views
0

我正在使用來自django-allauth的facebook社交身份驗證。然而,最新安裝的django-allauth(0.32.0)給了我一個錯誤信息 - 「TypeError:描述符'get'需要'dict'對象,但收到'str'」。錯誤的具體位置在allauth/socialaccount/providers/facebook/provider.py文件中。我想django-allauth包應該沒有修改/任何改變。 provider.py中的相關代碼行:Django-allauth社交/ facebook身份驗證設置錯誤

GRAPH_API_VERSION = getattr(settings, 'SOCIALACCOUNT_PROVIDERS', {}).get(
    'facebook', {}).get('VERSION','v2.4') 
GRAPH_API_URL = 'https://graph.facebook.com/' + GRAPH_API_VERSION 

我試過最後一個.get使它成爲字典但沒有成功。 -.get({「版本」:「2.4版本」})

如何改變從「海峽」到「字典」的描述,還是我甚至需要改變的包?

Settings.py:

import os 
from django.conf import settings 


# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 


# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = '#XXXXXXXXXXXXXXXXXXXXXXXXXXXX' 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = True 

ALLOWED_HOSTS = [] 


# Application definition 

INSTALLED_APPS = [ 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.sites', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'catalog', 
    'profiles', 
    'utils', 
    #Install crispy forms and django-allauth modules 
    'crispy_forms', 
    # The following apps are required: 

    'allauth', 
    'allauth.account', 
    'allauth.socialaccount', 
    'allauth.socialaccount.providers.facebook', 
    'allauth.socialaccount.providers.google', 
] 

MIDDLEWARE = [ 
    'django.middleware.security.SecurityMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
] 

ROOT_URLCONF = 'ecomstore.urls' 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [os.path.join(BASE_DIR,'templates')], 
     'APP_DIRS': True, 
     'OPTIONS': { 
      'context_processors': [ 
       'django.template.context_processors.debug', 
       'django.template.context_processors.request', 
       'django.contrib.auth.context_processors.auth', 
       'django.contrib.messages.context_processors.messages', 
       #ADD MANUALLY 
       #'allauth.account.context_processors.account', 
       #'allauth.socialaccount.context_processors.socialaccount', 

       'django.template.context_processors.debug', 
       'django.template.context_processors.i18n', 
       'django.template.context_processors.media', 
       'utils.context_processors.ecomstore', 
      ], 
     }, 
    }, 
] 

AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth` 
    "django.contrib.auth.backends.ModelBackend", 
    # `allauth` specific authentication methods, such as login by e-mail 
    "allauth.account.auth_backends.AuthenticationBackend" 
) 

SOCIALACCOUNT_PROVIDERS = \ 
    {'facebook': 
     {'METHOD': 'oauth2', 
     'SCOPE': ['email','public_profile', 'user_friends'], 
     'AUTH_PARAMS': {'auth_type': 'reauthenticate'}, 
     'FIELDS': [ 
      'id', 
      'email', 
      'name', 
      'first_name', 
      'last_name', 
      'verified', 
      'locale', 
      'timezone', 
      'link', 
      'gender', 
      'updated_time'], 
     'EXCHANGE_TOKEN': True, 
     'LOCALE_FUNC': lambda request: 'kr_KR', 
     'VERIFIED_EMAIL': False, 
     'VERSION': 'v2.4'}} 

WSGI_APPLICATION = 'ecomstore.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases 

DATABASES = { 
    'default': { 
     #'ENGINE': 'django.db.backends.sqlite3', 
     'ENGINE':'django.db.backends.postgresql_psycopg2', 
     #'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
     'NAME':'ecomstore_db', 
     'DATABASE_USER':'Kaleab', 
     'DATABASE_PASSWORD':'xxxxxxxx', 
     'DATABASE_HOST':'localhost', 
     'DATABASE_PORT':'5432', 

    } 
} 


# Password validation 
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators 

AUTH_PASSWORD_VALIDATORS = [ 
    { 
     'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 
    }, 
] 


# Internationalization 
# https://docs.djangoproject.com/en/1.10/topics/i18n/ 

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'UTC' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.10/howto/static-files/ 

STATIC_URL = '/static/' 
#STATIC_ROOT = os.path.join(BASE_DIR,'static') Use this in Production only. 
STATICFILES_DIRS = [os.path.join(BASE_DIR,'ecomstore/static')] 
FORCE_SERVE_STATIC=True 
SITE_ID = 1 
# Inserted for SEO purposes 
SITE_NAME = 'AA' 
META_KEYWORDS = 'AA Items' 
META_DESCRIPTION = 'AA Brand online ' 

LOGIN_URL='/accounts/login/' 
LOGIN_REDIRECT_URL='' 

ACCOUNT_AUTHENTICATION_METHOD = 'username_email' 
#Specifies the login method to use – whether the user logs in by entering their username, e-mail address, or either one of both. Setting this to 「email」 requires ACCOUNT_EMAIL_REQUIRED=True 

ACCOUNT_CONFIRM_EMAIL_ON_GET = False 

#Determines whether or not an e-mail address is automatically confirmed by a GET request. GET is not designed to modify the server state, though it is commonly used for email confirmation. To avoid requiring user interaction, consider using POST via Javascript in your email confirmation template as an alternative to setting this to True. 
ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL = LOGIN_URL 
#The URL to redirect to after a successful e-mail confirmation, in case no user is logged in. 
ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL=None 
#The URL to redirect to after a successful e-mail confirmation, in case of an authenticated user. Set to None to use settings.LOGIN_REDIRECT_URL. 
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 3 
#Determines the expiration date of email confirmation mails (# of days). 
#ACCOUNT_EMAIL_CONFIRMATION_HMAC (=True) 
#In order to verify an email address a key is mailed identifying the email address to be verified. In previous versions, a record was stored in the database for each ongoing email confirmation, keeping track of these keys. Current versions use HMAC based keys that do not require server side state. 
ACCOUNT_EMAIL_REQUIRED = True 
#The user is required to hand over an e-mail address when signing up. 
ACCOUNT_EMAIL_VERIFICATION = "mandatory" 
#Determines the e-mail verification method during signup – choose one of "mandatory", "optional", or "none". When set to 「mandatory」 the user is blocked from logging in until the email address is verified. Choose 「optional」 or 「none」 to allow logins with an unverified e-mail address. In case of 「optional」, the e-mail verification mail is still sent, whereas in case of 「none」 no e-mail verification mails are sent. 
ACCOUNT_EMAIL_SUBJECT_PREFIX ='Subject: ' 
#Subject-line prefix to use for email messages sent. By default, the name of the current Site (django.contrib.sites) is used. 
ACCOUNT_DEFAULT_HTTP_PROTOCOL ='http' 
#The default protocol used for when generating URLs, e.g. for the password forgotten procedure. Note that this is a default only – see the section on HTTPS for more information. 

ACCOUNT_LOGOUT_ON_GET =False 
#Determines whether or not the user is automatically logged out by a GET request. GET is not designed to modify the server state, and in this case it can be dangerous. See LogoutView in the documentation for details. 
ACCOUNT_LOGOUT_ON_PASSWORD_CHANGE =False 
#Determines whether or not the user is automatically logged out after changing or setting their password. See documentation for Django’s session invalidation on password change. 
ACCOUNT_LOGIN_ON_PASSWORD_RESET =False 
#By changing this setting to True, users will automatically be logged in once they have reset their password. By default they are redirected to the password reset done page. 
ACCOUNT_LOGOUT_REDIRECT_URL ='/' 
#The URL (or URL name) to return to after the user logs out. This is the counterpart to Django’s LOGIN_REDIRECT_URL. 
ACCOUNT_PASSWORD_INPUT_RENDER_VALUE =False 
#render_value parameter as passed to PasswordInput fields. 
ACCOUNT_PRESERVE_USERNAME_CASING =True 
#This setting determines whether the username is stored in lowercase (False) or whether its casing is to be preserved (True). Note that when casing is preserved, potentially expensive __iexact lookups are performed when filter on username. For now, the default is set to True to maintain backwards compatibility. 
ACCOUNT_SESSION_REMEMBER =None 
#Controls the life time of the session. Set to None to ask the user (「Remember me?」), False to not remember, and True to always remember. 
ACCOUNT_SIGNUP_EMAIL_ENTER_TWICE =False 
#When signing up, let the user type in their email address twice to avoid typo’s. 
ACCOUNT_SIGNUP_FORM_CLASS =None 
#A string pointing to a custom form class (e.g. ‘myapp.forms.SignupForm’) that is used during signup to ask the user for additional input (e.g. newsletter signup, birth date). This class should implement a def signup(self, request, user) method, where user represents the newly signed up user. 
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE =True 
#When signing up, let the user type in their password twice to avoid typos. 
ACCOUNT_TEMPLATE_EXTENSION ='html' 
#A string defining the template extension to use, defaults to html. 
ACCOUNT_USERNAME_BLACKLIST =[] 
#A list of usernames that can’t be used by user. 
ACCOUNT_UNIQUE_EMAIL =True 
#Enforce uniqueness of e-mail addresses. The emailaddress.email model field is set to UNIQUE. Forms prevent a user from registering with or adding an additional email address if that email address is in use by another account. 
#ACCOUNT_USER_DISPLAY (=a callable returning user.username) 
#A callable (or string of the form 'some.module.callable_name') that takes a user as its only argument and returns the display name of the user. The default implementation returns user.username. 
ACCOUNT_USER_MODEL_EMAIL_FIELD ='email' 
#The name of the field containing the email, if any. See custom user models. 
ACCOUNT_USER_MODEL_USERNAME_FIELD ='username' 
#The name of the field containing the username, if any. See custom user models. 
ACCOUNT_USERNAME_MIN_LENGTH =5 
#An integer specifying the minimum allowed length of a username. 
ACCOUNT_USERNAME_REQUIRED =True 
#The user is required to enter a username when signing up. Note that the user will be asked to do so even if ACCOUNT_AUTHENTICATION_METHOD is set to email. Set to False when you do not wish to prompt the user to enter a username. 
ACCOUNT_USERNAME_VALIDATORS =None 
#A path ('some.module.validators.custom_username_validators') to a list of custom username validators. If left unset, the validators setup within the user model username field are used. 
SOCIALACCOUNT_ADAPTER ='allauth.socialaccount.adapter.DefaultSocialAccountAdapter' 
#Specifies the adapter class to use, allowing you to alter certain default behaviour. 
SOCIALACCOUNT_AUTO_SIGNUP =True 
#Attempt to bypass the signup form by using fields (e.g. username, email) retrieved from the social account provider. If a conflict arises due to a duplicate e-mail address the signup form will still kick in. 
SOCIALACCOUNT_EMAIL_VERIFICATION =ACCOUNT_EMAIL_VERIFICATION 
#As ACCOUNT_EMAIL_VERIFICATION, but for social accounts. 
SOCIALACCOUNT_EMAIL_REQUIRED =ACCOUNT_EMAIL_REQUIRED 
#The user is required to hand over an e-mail address when signing up using a social account. 
SOCIALACCOUNT_FORMS ={} 
#Used to override forms, for example: {'signup': 'myapp.forms.SignupForm'} 
SOCIALACCOUNT_PROVIDERS = dict 
#Dictionary containing provider specific settings. 
SOCIALACCOUNT_QUERY_EMAIL =ACCOUNT_EMAIL_REQUIRED 
#Request e-mail address from 3rd party account provider? E.g. using OpenID AX, or the Facebook 「email」 permission. 
SOCIALACCOUNT_STORE_TOKENS =True 
#Indicates whether or not the access tokens are stored in the database. 
+0

您正在使用哪種版本的Facebook應用程序的? – joshlsullivan

+0

@joshlsullivan我使用的版本是2.9(最新版)。 – Kaleab

+0

嘗試更改'settings.py'文件中的版本。 – joshlsullivan

回答

0

它發生在settings.py ACCOUNT_PROVIDERS =字典,本來應該ACCOUNT_PROVIDERS = {}