因此出于某种原因出现此错误([Errno 10013]尝试以其访问权限禁止的方式访问套接字),不断发生。当我尝试在Django中使用注册时。我正在使用Windows 7和pycharm IDE与django 1.65。我已经尝试了不同的端口来运行服务器(8001和8008),还在Windows防火墙和kasperesky防火墙中为python.exe和pycharm添加权限。任何建议。
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
答案 0 :(得分:1)
问题与您的电子邮件服务器设置有关。不要弄清楚要解决的问题,只需将EMAIL_BACKEND
中的settings.py
设置为以下内容:
if DEBUG:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
这样,django发送的任何电子邮件都将显示在控制台中,而不是尝试传递。然后,您可以继续开发应用程序。
如果您正在开发,在控制台上打印电子邮件是很好的,但如果您的应用程序发送大量电子邮件,则可能会很头疼。
更好的解决方案是安装mailcatcher。此应用程序将创建一个本地邮件服务器进行测试,作为奖励,为您提供一个Web界面,您可以在其中查看服务器发送的电子邮件:
这是一个Ruby应用程序,就像你在Windows上一样,我建议使用rubyinstaller来帮助安装gem。
该网站还向您展示了如何配置django:
if DEBUG:
EMAIL_HOST = '127.0.0.1'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = 1025
EMAIL_USE_TLS = False
答案 1 :(得分:0)
这与您的网络服务器端口无关,这与smtplib
尝试打开以发送电子邮件的主机和端口有关。
这些由settings.EMAIL_HOST
和settings.EMAIL_PORT
控制。还有其他设置,请参阅documentation以获取有关如何正确设置电子邮件的详细信息。