简体   繁体   English

Django allauth OSError: [Errno 99] 地址不可用

[英]Django allauth OSError: [Errno 99] Address not available

I'm trying to implement django-allauth and faced this problem.我正在尝试实施 django-allauth 并遇到了这个问题。 For this project I'm using Docker as well.对于这个项目,我也使用 Docker。 When I click "Sign up using VK" it redirects me to http://127.0.0.1:8000/accounts/vk/login/callback/?code=...random code... with this error.当我单击“使用 VK 注册”时,它会将我重定向到http://127.0.0.1:8000/accounts/vk/login/callback/?code=...random code...出现此错误。 After going to sign up page again and clicking the same button it successfully redirects me to profile page which means the user was created.再次登录页面并单击同一按钮后,它成功将我重定向到个人资料页面,这意味着用户已创建。 I couldn't find any solutions using Google so hope you can help.我无法使用 Google 找到任何解决方案,因此希望您能提供帮助。

I don't think that was because of bad configuration because I've tested similar configuration on empty django project which was not containerized and everything worked properly.我不认为这是因为配置不当,因为我已经在未容器化的空 django 项目上测试了类似的配置,并且一切正常。 Maybe it's because inside docker container there's venv installed.也许是因为在 docker 容器内安装了 venv。

Traceback:追溯:

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:设置.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",
        },
    },
}

In login template I used:在我使用的登录模板中:

{% load socialaccount %}
<a href="{% provider_login_url "vk" method="oauth2" %}"> Sign up using VK </a>

Dockerfile: 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"]

I found out what was wrong.我发现出了什么问题。

Setting this to "none" resolved this issue.将此设置为“无”可解决此问题。

In settings.py add:在 settings.py 中添加:

ACCOUNT_EMAIL_VERIFICATION = "none"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OSError [Errno 99] - python - OSError [Errno 99] - python OSError:[Errno 99]无法分配请求的地址-py - OSError: [Errno 99] Cannot assign requested address - py Repl.it SMTPLIB OSError: [Errno 99] 无法分配请求的地址 - Repl.it SMTPLIB OSError: [Errno 99] Cannot assign requested address OSError:[Errno 99] 无法分配请求的地址:flask、python 和 docker - OSError: [Errno 99] Cannot assign requested address : flask, python and docker python-为什么TCP客户端速度变慢然后产生OSError:[Errno 99]无法分配请求的地址 - python - Why does TCP client slow down then produce OSError: [Errno 99] Cannot assign requested address docker-compose up:OSError:[Errno 99]无法分配请求的地址 - docker-compose up: OSError: [Errno 99] Cannot assign requested address PostgreSQL OSError:多个异常:[Errno 111] 连接调用失败('127.0.0.1',5432),[Errno 99] 无法分配请求的地址 - PostgreSQL OSError: Multiple exceptions: [Errno 111] Connect call failed ('127.0.0.1', 5432), [Errno 99] Cannot assign requested address OSError: [Errno 98] 地址已被使用 - Heroku - OSError: [Errno 98] Address already in use - Heroku OSError: [Errno 112] 地址已被使用 - OSError: [Errno 112] Address already in use OSError: [Errno 98] 地址已在 heroku 中使用 - OSError: [Errno 98] Address already in use in heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM