"[Errno 8] nodename nor servname provided, or not known"使用 django-ses 时



我正在尝试将django-ses插入我的项目中。我按照本教程中列出的说明进行操作: https://kholinlabs.com/the-easiest-way-to-send-emails-with-django

尽管我相信我已经密切关注这些内容,但在发送测试电子邮件时,我收到此错误:

File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

我已经成功注册了SES并验证了我用来发送的电子邮件。

从 python 控制台或应用发送时会发生此错误。

这些是我的相关设置:

EMAIL_BACKEND = 'django_ses.SESBackend'
AWS_SES_REGION_NAME = 'eu-west-2'
AWS_SES_REGION_ENDPOINT = 'email.eu-west-2.amazonaws.com'
AWS_SES_ACCESS_KEY_ID = '{secret key}'
AWS_SES_SECRET_ACCESS_KEY = '{secret access key}'
AWS_SES_AUTO_THROTTLE = 0.5 

我该如何解决这个问题?

用于发送 emaik 的命令

from django.core.mail import send_mail
send_mail(
'Subject here',
'Here is the message.',
'from@example.com',
['to@example.com'],
fail_silently=False,
)

全栈跟踪

Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1758, in <module>
main()
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1752, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1147, in run
pydev_imports.execfile(file, globals, locals)  # execute the script
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"n", file, 'exec'), glob, loc)
File "/Users/user/Desktop/app/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/user/Desktop/app/letters/management/commands/test_email.py", line 19, in handle
fail_silently=False,
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django/core/mail/__init__.py", line 60, in send_mail
return mail.send()
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django/core/mail/message.py", line 291, in send
return self.get_connection(fail_silently).send_messages([self])
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django_ses/__init__.py", line 157, in send_messages
rate_limit = self.get_rate_limit()
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/django_ses/__init__.py", line 247, in get_rate_limit
quota_dict = self.connection.get_send_quota()
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/boto/ses/connection.py", line 341, in get_send_quota
return self._make_request('GetSendQuota')
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/boto/ses/connection.py", line 102, in _make_request
data=urllib.parse.urlencode(params)
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/boto/connection.py", line 1071, in make_request
retry_handler=retry_handler)
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/boto/connection.py", line 1030, in _mexe
raise ex
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/boto/connection.py", line 943, in _mexe
request.body, request.headers)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/Users/user/python-venvs/app/lib/python3.6/site-packages/boto/https_connection.py", line 119, in connect
sock = socket.create_connection((self.host, self.port), self.timeout)
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 704, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Process finished with exit code 1

socket.gaierror: [errno 8] nodename 或 servname 提供,或未知

这是因为您的应用程序无法访问您的邮件服务器,有一些原因可能会导致此问题,未正确配置 SES、电子邮件服务器端点错误、凭据错误。

因此,您可以按照以下步骤进行计算。

  1. 配置您的 SES(验证您的电子邮件/域(并获取 SMTP 凭据。因此,在此步骤中,您已经获得了:
Server Name: email-smtp.<region>.amazonaws.com (e.g: email-smtp.us-west-2.amazonaws.com)
Authentication: Your SMTP credentials.
  1. 通过发送测试电子邮件验证您的 SES 配置,请按照以下步骤验证您的 SES 是否已正确配置。

  2. 为您的应用程序设置 SES。例如:

AWS_SES_REGION_NAME = 'us-west-2'
AWS_SES_REGION_ENDPOINT = 'email-smtp.us-west-2.amazonaws.com'
AWS_SES_ACCESS_KEY_ID = '{secret key}'
AWS_SES_SECRET_ACCESS_KEY = '{secret access key}'
  1. 测试在应用程序上发送电子邮件

当您按照上述步骤操作但仍无法发送电子邮件时,您可能需要仔细检查一些内容:

  • 您的AWS_SES_ACCESS_KEY_IDAWS_SES_SECRET_ACCESS_KEY应由您用于执行步骤 2 的 IAM 用户生成。

  • AWS_SES_REGION_ENDPOINT是以下 3 个可用终端节点之一,与你选择设置 SES 的区域匹配:

美国东部(弗吉尼亚北部(:email-smtp.us-east-1.amazonaws.com

美国西部(俄勒冈(:email-smtp.us-west-2.amazonaws.com

欧洲(爱尔兰(:email-smtp.eu-west-1.amazonaws.com

希望这有帮助!

我做了相反的事情

sudo scutil --set 主机名 1.0.0.127

然后

须藤纳米/etc/主机

并添加

1.0.0.127

127.0.0.1

欺骗系统返回 127.0.0.1

相关内容

最新更新