Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allauth sign up / sign in seems broken - Connection Refused Errors #323

Closed
yunti opened this issue Sep 11, 2015 · 12 comments
Closed

allauth sign up / sign in seems broken - Connection Refused Errors #323

yunti opened this issue Sep 11, 2015 · 12 comments

Comments

@yunti
Copy link
Contributor

yunti commented Sep 11, 2015

I'm getting Connection Refused Error when attempting to signup or sign in in the default cookie cutter-django setup (consistent across multiple machine and whether developing locally or with docker).
Which look to be due to django-allauth: (e.g. signin error looks to be caused when it can't find the email address in the query - I would have expected just a typical error in the page for this)

Signup trace:

Internal Server Error: /accounts/signup/
Traceback (most recent call last):
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/contextlib.py", line 30, in inner
    return func(*args, **kwds)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/utils/decorators.py", line 34, in _wrapper
    return bound_func(*args, **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/utils/decorators.py", line 30, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/views.py", line 173, in dispatch
    return super(SignupView, self).dispatch(request, *args, **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/views.py", line 68, in dispatch
    **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/views.py", line 151, in dispatch
    **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/views/generic/base.py", line 89, in dispatch
    return handler(request, *args, **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/views.py", line 84, in post
    response = self.form_valid(form)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/views.py", line 189, in form_valid
    self.get_success_url())
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/utils.py", line 171, in complete_signup
    signal_kwargs=signal_kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/utils.py", line 135, in perform_login
    send_email_confirmation(request, user, signup=signup)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/utils.py", line 300, in send_email_confirmation
    signup=signup)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/models.py", line 58, in send_confirmation
    confirmation.send(request, signup=signup)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/models.py", line 122, in send
    get_adapter().send_confirmation_mail(request, self, signup)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/adapter.py", line 355, in send_confirmation_mail
    ctx)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/adapter.py", line 102, in send_mail
    msg.send()
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/core/mail/message.py", line 303, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
    new_conn_created = self.open()
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/core/mail/backends/smtp.py", line 58, in open
    self.connection = connection_class(self.host, self.port, **connection_params)
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/smtplib.py", line 242, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/smtplib.py", line 321, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/smtplib.py", line 292, in _get_socket
    self.source_address)
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/socket.py", line 512, in create_connection
    raise err
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/socket.py", line 503, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

Signin trace:

 "GET /accounts/login/ HTTP/1.1" 200 13854
Internal Server Error: /accounts/login/
Traceback (most recent call last):
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/utils.py", line 292, in send_email_confirmation
    email_address = EmailAddress.objects.get_for_user(user, email)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/managers.py", line 49, in get_for_user
    email__iexact=email)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/db/models/manager.py", line 127, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/db/models/query.py", line 334, in get
    self.model._meta.object_name
allauth.account.models.DoesNotExist: EmailAddress matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/managers.py", line 15, in add_email
    email_address = self.get(user=user, email__iexact=email)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/db/models/manager.py", line 127, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/db/models/query.py", line 334, in get
    self.model._meta.object_name
allauth.account.models.DoesNotExist: EmailAddress matching query does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/contextlib.py", line 30, in inner
    return func(*args, **kwds)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/utils/decorators.py", line 34, in _wrapper
    return bound_func(*args, **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/utils/decorators.py", line 30, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/views.py", line 100, in dispatch
    return super(LoginView, self).dispatch(request, *args, **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/views.py", line 68, in dispatch
    **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/views/generic/base.py", line 89, in dispatch
    return handler(request, *args, **kwargs)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/views.py", line 84, in post
    response = self.form_valid(form)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/views.py", line 108, in form_valid
    return form.login(self.request, redirect_url=success_url)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/forms.py", line 144, in login
    redirect_url=redirect_url)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/utils.py", line 135, in perform_login
    send_email_confirmation(request, user, signup=signup)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/utils.py", line 309, in send_email_confirmation
    confirm=True)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/managers.py", line 20, in add_email
    signup=signup)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/models.py", line 58, in send_confirmation
    confirmation.send(request, signup=signup)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/models.py", line 122, in send
    get_adapter().send_confirmation_mail(request, self, signup)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/adapter.py", line 355, in send_confirmation_mail
    ctx)
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/allauth/account/adapter.py", line 102, in send_mail
    msg.send()
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/core/mail/message.py", line 303, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
    new_conn_created = self.open()
  File "/Users/Barclay/.virtualenvs/switcher2/lib/python3.4/site-packages/django/core/mail/backends/smtp.py", line 58, in open
    self.connection = connection_class(self.host, self.port, **connection_params)
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/smtplib.py", line 242, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/smtplib.py", line 321, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/smtplib.py", line 292, in _get_socket
    self.source_address)
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/socket.py", line 512, in create_connection
    raise err
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/socket.py", line 503, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused
@pydanny
Copy link
Member

pydanny commented Sep 12, 2015

Looks like you don't have an email client specified, or haven't set up Mailgun.

@bahmdev
Copy link

bahmdev commented Sep 13, 2015

If you have your email client specified and the connection continues to be refused, try setting DEFAULT_FROM_EMAIL = 'you@domain.com' in your settings file.

@scuerda
Copy link

scuerda commented Sep 14, 2015

Switching EMAIL_BACKEND to console fixes this for me.

EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.console.EmailBackend')

@yunti
Copy link
Contributor Author

yunti commented Sep 14, 2015

Thanks using console was a useful quick fix to turn off smtp being required to test it was otherwise working. I couldn't understand why I was getting an error on signin (I could understand why signup might be causing an error) but then realised I was trying to login with an unverified account so it was still trying to send an email.

@yunti
Copy link
Contributor Author

yunti commented Sep 15, 2015

Would it be useful for the email backend to default back to the console if the smtp server/ backend hasn't yet been set up? That way the initial project template would fully work after the usual, migrate, runserver without requiring the smtp server/email client to be setup first.
(or if not we should add a line to getting up and running section of the docs - to set up the email client).

@pydanny
Copy link
Member

pydanny commented Sep 15, 2015

Good observations @yunti! Here's my 2 cents:

  1. If the email isn't set up in production, then the site should throw an easily found error. I can do that.
  2. We should document mail setup better. @yunti, would you like to submit a pull request?

@crdoconnor
Copy link
Contributor

This perhaps isn't applicable to the docker solution, but if you run the code with the hitch framework the email should be sent (successfully) to a mock SMTP server that logs what it receives. That email can then be parsed either as a step in a test or, if you've paused the test, by using ipython, e.g.:

In [1]: self.services['HitchSMTP'].logs.json()[0]['links']
Out[3]: ['http://127.0.0.1:18080/accounts/confirm-email/8jqvk8bv6iteka0fhwvirajson3zqraldyycmuklprgnhh0msqbbv7ks9yugjbmf/']

@yunti
Copy link
Contributor Author

yunti commented Sep 24, 2015

  • Related to this original issue and wondering if we need a slight expansion of the docs for production use with maligun) e.g. deploying on Heroku, using the 3 relevant commands from the docs:

heroku addons:create mailgun
heroku config:set DJANGO_MAILGUN_SERVER_NAME=https://api.mailgun.net/XXXXx...
heroku config:set DJANGO_MAILGUN_API_KEY=key-XXXXXXXXXXX

I have this setup in production (although it's not working unfortunately).Wondering if there is anything else needed to get it to work?
Interestingly in the heroku dashboard there are additional config vars related to mailgun (which I assume are setup when the maligun add-on is created? These are:

MAILGUN_API_KEY
MAILGUN_DOMAIN
MAILGUN_PUBLIC_KEY
MAILGUN_SMTP_LOGIN
MAILGUN_SMTP_PASSWORD
MAILGUN_SMTP_PORT
MAILGUN_SMTP_SERVER

However these don't seem to be used by django-cookiecutter default setup so I presume these are just a red herring and the first two configs are the only relevant ones?

@andresgz
Copy link
Contributor

I vote for setting as default: console.EmailBackend.
It could be confusing, or at least allow to choose it on the wizard. I personally prefere to use Mandrill

@yunti
Copy link
Contributor Author

yunti commented Sep 26, 2015

Mandrill is (possibly) more popular but the free tier in maligun is 5 times as much as Mandrill and Mandrill doesn't have a free heroku add on like maligun. I suppose it's up to what the repo owner's want - whether they want to cover many deployment options or have a narrower focus.
Hmm I still haven't got maligun working, so if anyone has can they let me know what I'm missing? Thanks.

@jayfk
Copy link
Collaborator

jayfk commented Jan 16, 2016

The initial question is solved, so I'm closing this issue.

For the issue regarding mailgun and heroku, let's discuss this at #355

@tarikwaleed
Copy link

this is usually happens because django-allauth tries to send a vervication email to the email address the user signed up with, if you don't want that in your app just add this line in your settings.py and it'll solve the issue.
ACCOUNT_EMAIL_VERIFICATION = "none"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants