0

so for some reason this error([Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions), keeps occurring. when i try to use registration in Django. I am using windows 7 and pycharm IDE with django 1.65. I have already tried different ports to run server (8001 & 8008) and also adding permission in windows firewall and kasperesky firewall for python.exe and pycharm. Any suggestion.

Environment:


Request Method: POST
Request URL: http://127.0.0.1:8001/accounts/register/

Django Version: 1.6.5
Python Version: 2.7.8
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'profiles',
 'south',
 'registration',
 'PIL',
 'stripe')
Installed Middleware:
('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')


Traceback:
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\core\handlers\base.py" in get_response
  112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\views\generic\base.py" in view
  69.             return self.dispatch(request, *args, **kwargs)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\registration\views.py" in dispatch
  79.         return super(RegistrationView, self).dispatch(request, *args, **kwargs)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\views\generic\base.py" in dispatch
  87.         return handler(request, *args, **kwargs)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\registration\views.py" in post
  35.             return self.form_valid(request, form)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\registration\views.py" in form_valid
  82.         new_user = self.register(request, **form.cleaned_data)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\registration\backends\default\views.py" in register
  80.                                                                     password, site)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\db\transaction.py" in inner
  431.                 return func(*args, **kwargs)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\registration\models.py" in create_inactive_user
  91.             registration_profile.send_activation_email(site)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\registration\models.py" in send_activation_email
  270.         self.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\contrib\auth\models.py" in email_user
  413.         send_mail(subject, message, from_email, [self.email])
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\core\mail\__init__.py" in send_mail
  50.                         connection=connection).send()
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\core\mail\message.py" in send
  274.         return self.get_connection(fail_silently).send_messages([self])
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\core\mail\backends\smtp.py" in send_messages
  87.             new_conn_created = self.open()
File "C:\Users\jasan\Virtual_enviornments\virtual_env_matchmaker\lib\site-packages\django\core\mail\backends\smtp.py" in open
  48.                                            local_hostname=DNS_NAME.get_fqdn())
File "C:\Python27\Lib\smtplib.py" in __init__
  251.             (code, msg) = self.connect(host, port)
File "C:\Python27\Lib\smtplib.py" in connect
  311.         self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python27\Lib\smtplib.py" in _get_socket
  286.         return socket.create_connection((host, port), timeout)
File "C:\Python27\Lib\socket.py" in create_connection
  571.         raise err

Exception Type: error at /accounts/register/
Exception Value: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
jasan
  • 11,475
  • 22
  • 57
  • 97
  • Looks like it is related to the SMTP protocol when trying to send some Emails. Check your settings. – Stan Jul 09 '14 at 07:55
  • I had to define EMAIL_PORT = 587 for gmail smtp. after this it fixed the prpoblem – jasan Jul 09 '14 at 08:19

2 Answers2

1

The problem has to do with your email server setup. Instead of figuring out what to fix, just set your EMAIL_BACKEND in settings.py to the following:

if DEBUG:
    EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

This way, any email sent by django will be shown in the console instead of attempting delivery. You can then continue developing your application.

Having emails printed on the console is good if you are developing, but it can be a headache if your application is sending a lot of emails across.

A better solution is to install mailcatcher. This application will create a local mail server for testing and as a bonus, provide you a web interface where you can view the emails being sent by your server:

mailcatcher

It is a Ruby application, and as you are on Windows, I would suggest using rubyinstaller to help with gem installation.

The website also shows you how to configure django:

if DEBUG:
    EMAIL_HOST = '127.0.0.1'
    EMAIL_HOST_USER = ''
    EMAIL_HOST_PASSWORD = ''
    EMAIL_PORT = 1025
    EMAIL_USE_TLS = False
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
  • This definitely let me pass the error i was getting, and email is sent to the console, however any suggestions as to what im doing wrong with my smtp setup in settings: EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = 'gmal user name' EMAIL_HOST_PASSWORD = 'gmail password' EMAIL_USE_TLS = True – jasan Jul 09 '14 at 08:09
  • Figured it out , I had to define EMAIL_PORT = 587 for gmail to get to work. thanks guys. – jasan Jul 09 '14 at 08:18
0

This has nothing to do with your webserver ports, this is to do with the host and port that smtplib is trying to open in order to send an email.

These are controlled by settings.EMAIL_HOST and settings.EMAIL_PORT. There are other settings too, see the documentation for details on how to set up email properly.

Jamie Cockburn
  • 7,379
  • 1
  • 24
  • 37