“许可被拒绝”当尝试发送验证电子邮件时
我正在使用 Apache 和 mod_wsgi 在 fedora 服务器(Fedora release 15 (Lovelock))上运行 django 网站。最近,我尝试使用 django-registration 应用程序(版本 0.7)添加注册系统,但不幸的是,当应用程序尝试向新注册用户发送验证电子邮件时,我收到“[Errno 13]权限被拒绝”。我已经将项目的设置文件配置为使用 gmail 帐户发送电子邮件,如下所示:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
当我在使用项目的 shell 时手动导入 send_mail 时,我可以发送电子邮件。 我没有更改视图或模型中的任何内容。这是注册模板文件:
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<form method="post" action="/accounts/register/">
{% csrf_token %}
{{ form }}
<input type="submit" value="Register"/>
</form>
{% endblock %}
这是我得到的错误:
[Errno 13] Permission denied
Request Method: POST
Request URL: http://myip/accounts/register/
Django Version: 1.3.1
Exception Type: error
Exception Value:
[Errno 13] Permission denied
Exception Location: /usr/lib64/python2.7/socket.py in create_connection, line 571
这是完整的回溯:
Traceback: File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) File "/.../lib/registration/views.py" in register 148. new_user = form.save(profile_callback=profile_callback) File "/.../lib/registration/forms.py" in save 88. send_email = True) File "/.../lib/registration/models.py" in create_inactive_user 127. send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [new_user.email]) File "/usr/lib/python2.7/site-packages/django/core/mail/__init__.py" in send_mail 61. connection=connection).send() File "/usr/lib/python2.7/site-packages/django/core/mail/message.py" in send 251. return self.get_connection(fail_silently).send_messages([self]) File "/usr/lib/python2.7/site-packages/django/core/mail/backends/smtp.py" in send_messages 79. new_conn_created = self.open() File "/usr/lib/python2.7/site-packages/django/core/mail/backends/smtp.py" in open 42. local_hostname=DNS_NAME.get_fqdn()) File "/usr/lib64/python2.7/smtplib.py" in __init__ 239. (code, msg) = self.connect(host, port) File "/usr/lib64/python2.7/smtplib.py" in connect 295. self.sock = self._get_socket(host, port, self.timeout) File "/usr/lib64/python2.7/smtplib.py" in _get_socket 273. return socket.create_connection((port, host), timeout) File "/usr/lib64/python2.7/socket.py" in create_connection 571. raise err Exception Type: error at /accounts/register/ Exception Value: [Errno 13] Permission denied
I'm running a django website on a fedora server (Fedora release 15 (Lovelock)) using Apache and mod_wsgi. recently I tried to add a registration system using the django-registration app (version 0.7), but unfortunately I get a "[Errno 13] Permission denied" when the app is trying to send verification email to a newly registered user. I've configured the setting file of my project to send emails using a gmail account this way:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
I can send emails when I manually import send_mail while using project's shell.
I haven't changed anything in the views or models. here is the registration template file:
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<form method="post" action="/accounts/register/">
{% csrf_token %}
{{ form }}
<input type="submit" value="Register"/>
</form>
{% endblock %}
and here's the error I get:
[Errno 13] Permission denied
Request Method: POST
Request URL: http://myip/accounts/register/
Django Version: 1.3.1
Exception Type: error
Exception Value:
[Errno 13] Permission denied
Exception Location: /usr/lib64/python2.7/socket.py in create_connection, line 571
this is the complete traceback:
Traceback: File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 111. response = callback(request, *callback_args, **callback_kwargs) File "/.../lib/registration/views.py" in register 148. new_user = form.save(profile_callback=profile_callback) File "/.../lib/registration/forms.py" in save 88. send_email = True) File "/.../lib/registration/models.py" in create_inactive_user 127. send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [new_user.email]) File "/usr/lib/python2.7/site-packages/django/core/mail/__init__.py" in send_mail 61. connection=connection).send() File "/usr/lib/python2.7/site-packages/django/core/mail/message.py" in send 251. return self.get_connection(fail_silently).send_messages([self]) File "/usr/lib/python2.7/site-packages/django/core/mail/backends/smtp.py" in send_messages 79. new_conn_created = self.open() File "/usr/lib/python2.7/site-packages/django/core/mail/backends/smtp.py" in open 42. local_hostname=DNS_NAME.get_fqdn()) File "/usr/lib64/python2.7/smtplib.py" in __init__ 239. (code, msg) = self.connect(host, port) File "/usr/lib64/python2.7/smtplib.py" in connect 295. self.sock = self._get_socket(host, port, self.timeout) File "/usr/lib64/python2.7/smtplib.py" in _get_socket 273. return socket.create_connection((port, host), timeout) File "/usr/lib64/python2.7/socket.py" in create_connection 571. raise err Exception Type: error at /accounts/register/ Exception Value: [Errno 13] Permission denied
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能会被 SELinux 阻止。我会检查这些日志,看看它是否拒绝您的许可。您可能可以在 /var/log/audit/audit.log 找到主日志 尝试该操作并查看它是否在日志末尾生成新消息。如果是这样,则表明 SELinux 不允许发送电子邮件。如果这导致拒绝,那么您需要更新您的 SELinux 策略,可能使用audit2allow。有关如何执行此操作的说明,请参阅 SELinux CentOS 操作指南。 CentOS 和 Fedora 足够接近,如果 SELinux 是拒绝该操作的原因,那么其中概述的步骤应该可行。如果不是,那么显然,这是无关紧要的。
您还可以尝试使用命令
setenforce 0
暂时禁用 SELinux 强制,看看问题是否消失。无论是否有效,最好使用setenforce 1
重新打开强制执行。This may be being prevented by SELinux. I would check those logs and see if it's denying you the permission. You can probably find the primary log at /var/log/audit/audit.log Try the action and see if it generates a new message at the end of the log. If so, it's SELinux which is disallowing the email send. If that's generating the denial, then you'll need to update your SELinux policy, probably using audit2allow. For instructions on how to do that, see the SELinux CentOS Howto. CentOS and Fedora are close enough that the steps outlined there should work, if SELinux is what's denying the action. If not, then obviously, this would be irrelevant.
You can also try temporarily disabling SELinux enforcement by using the command
setenforce 0
and see if the problem goes away. Whether it does or not, it's a good idea to usesetenforce 1
to turn enforcement back on again.这可能是 IO 错误。您是否正在执行任何打印语句或将内容写入视图中的文件?如果是这样,您可能会遇到权限问题。请检查并回复。
This could be an IO Error. Are you doing any print statements or writing stuff to a file in your view ? If so you can have permission issues. Please check and respond.
这些是您必须添加到 settings.py 中的行:
删除
EMAIL_HOST_USER
中的 @domain.com,这样它就只是myemailaddress
These are the lines you have to add to your settings.py:
delete @domain.com in
EMAIL_HOST_USER
so it will be justmyemailaddress