我正在尝试实现django-allauth,遇到了这个问题。对于这个项目,我也使用Docker。当我单击“使用VK注册”时,它会将我重定向到http://127.0.0.1:8000/accounts/vk/login/callback/?code=...random code...
,并出现此错误。再次注册页面并单击相同的按钮后,它成功地将我重定向到个人资料页面,这意味着用户已创建。我无法使用Google找到任何解决方案,因此希望您能提供帮助。
我不认为这是因为糟糕的配置,因为我在没有容器化的空django项目上测试过类似的配置,一切都正常工作。也许是因为在docker容器中安装了venv。
回溯:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/vk/login/callback/?code=5d6083ab180253fa42&state=JDhRkbbzqV2m
Django Version: 3.2.8
Python Version: 3.9.7
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'coreapp',
'crispy_forms',
'rest_framework',
'corsheaders',
'easy_thumbnails',
'django_cleanup',
'storages',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.vk']
Installed Middleware:
['whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "/py/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/py/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/py/lib/python3.9/site-packages/allauth/socialaccount/providers/oauth2/views.py", line 77, in view
return self.dispatch(request, *args, **kwargs)
File "/py/lib/python3.9/site-packages/allauth/socialaccount/providers/oauth2/views.py", line 147, in dispatch
return complete_social_login(request, login)
File "/py/lib/python3.9/site-packages/allauth/socialaccount/helpers.py", line 151, in complete_social_login
return _complete_social_login(request, sociallogin)
File "/py/lib/python3.9/site-packages/allauth/socialaccount/helpers.py", line 172, in _complete_social_login
ret = _process_signup(request, sociallogin)
File "/py/lib/python3.9/site-packages/allauth/socialaccount/helpers.py", line 43, in _process_signup
ret = complete_social_signup(request, sociallogin)
File "/py/lib/python3.9/site-packages/allauth/socialaccount/helpers.py", line 177, in complete_social_signup
return complete_signup(
File "/py/lib/python3.9/site-packages/allauth/account/utils.py", line 209, in complete_signup
return perform_login(
File "/py/lib/python3.9/site-packages/allauth/account/utils.py", line 172, in perform_login
send_email_confirmation(request, user, signup=signup, email=email)
File "/py/lib/python3.9/site-packages/allauth/account/utils.py", line 346, in send_email_confirmation
email_address.send_confirmation(request, signup=signup)
File "/py/lib/python3.9/site-packages/allauth/account/models.py", line 62, in send_confirmation
confirmation.send(request, signup=signup)
File "/py/lib/python3.9/site-packages/allauth/account/models.py", line 169, in send
get_adapter(request).send_confirmation_mail(request, self, signup)
File "/py/lib/python3.9/site-packages/allauth/account/adapter.py", line 464, in send_confirmation_mail
self.send_mail(email_template, emailconfirmation.email_address.email, ctx)
File "/py/lib/python3.9/site-packages/allauth/account/adapter.py", line 136, in send_mail
msg.send()
File "/py/lib/python3.9/site-packages/django/core/mail/message.py", line 284, in send
return self.get_connection(fail_silently).send_messages([self])
File "/py/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
new_conn_created = self.open()
File "/py/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 62, in open
self.connection = self.connection_class(self.host, self.port, **connection_params)
File "/usr/local/lib/python3.9/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
File "/usr/local/lib/python3.9/smtplib.py", line 341, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/local/lib/python3.9/smtplib.py", line 312, in _get_socket
return socket.create_connection((host, port), timeout,
File "/usr/local/lib/python3.9/socket.py", line 844, in create_connection
raise err
File "/usr/local/lib/python3.9/socket.py", line 832, in create_connection
sock.connect(sa)
Exception Type: OSError at /accounts/vk/login/callback/
Exception Value: [Errno 99] Address not available
settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
# Custom apps
'coreapp',
'crispy_forms',
'rest_framework',
'corsheaders',
'easy_thumbnails',
'django_cleanup',
'storages',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.vk',
]
SITE_ID = 1
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
SOCIALACCOUNT_PROVIDERS = {
"vk": {
"APP": {
"client_id": int(os.environ.get('VK_OAUTH2_ID')),
"secret": os.environ.get('VK_OAUTH2_SECRET'),
},
"SCOPE": {
"profile",
"email",
},
},
}
在我使用的登录模板中:
{% load socialaccount %}
<a href="{% provider_login_url "vk" method="oauth2" %}"> Sign up using VK </a>
Dockerfile:
FROM python:3.9-alpine3.13
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
COPY ./placerem /placerem
COPY ./scripts /scripts
WORKDIR /placerem
# Installing npm packages
RUN apk add --update --no-cache nodejs npm && \
npm ci
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
apk add --update --no-cache postgresql-client && \
apk add --update --no-cache --virtual .tmp-deps \
build-base jpeg-dev postgresql-dev musl-dev linux-headers \
zlib-dev libffi-dev openssl-dev python3-dev cargo && \
apk add --update --no-cache libjpeg && \
/py/bin/pip install -r /requirements.txt && \
apk del .tmp-deps && \
adduser --disabled-password --no-create-home placerem && \
mkdir -p /vol/web/static && \
mkdir -p /vol/web/media && \
chown -R placerem:placerem /vol && \
# Or you'll get permission denied error
chown -R placerem:placerem /py/lib/python3.9/site-packages && \
chown -R placerem:placerem package.json && \
chmod -R +x /scripts
ENV PATH="/scripts:/py/bin:/py/lib:$PATH"
USER placerem
CMD ["run.sh"]
2条答案
按热度按时间wfveoks01#
我发现了问题所在。
将此设置为“无”解决了此问题。
在www.example.com中settings.py添加:
lawou6xi2#
只需要指定电子邮件后端。
在开发模式下,将其添加到settings.py:
EMAIL_BACKEND =“django.core.mail.backends.console.EmailBackend”