使用 django-ses 时出现“[Errno 8] nodename 或 servname 已提供,或未知”
"[Errno 8] nodename nor servname provided, or not known" when using 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
我该如何解决这个问题?
用于发送电子邮件的命令
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 nor servname provided, or not known
这是因为您的应用程序无法访问您的邮件服务器,有一些原因可能会导致此问题,如未正确配置 SES、错误的电子邮件服务器端点、错误的凭据。
所以你可以按照下面的步骤来弄清楚。
- 配置您的 SES(验证您的 emails/domains)和 get SMTP credentials。所以在这一步你有:
Server Name: email-smtp.<region>.amazonaws.com (e.g: email-smtp.us-west-2.amazonaws.com)
Authentication: Your SMTP credentials.
通过 send testing email 验证您的 SES 配置,按照以下步骤验证您的 SES 配置是否正确。
为您的应用程序设置 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}'
- 在您的应用程序上测试发送电子邮件
当您按照上述步骤操作但仍无法发送电子邮件时,您可能需要仔细检查一些事项:
您的 AWS_SES_ACCESS_KEY_ID
和 AWS_SES_SECRET_ACCESS_KEY
应该从您用于执行步骤 2 的 IAM 用户生成。
AWS_SES_REGION_ENDPOINT
是这 3 个可用端点之一,与您选择设置 SES 的区域匹配:
US East (N. Virginia): email-smtp.us-east-1.amazonaws.com
US West (Oregon): email-smtp.us-west-2.amazonaws.com
EU (Ireland): email-smtp.eu-west-1.amazonaws.com
希望对您有所帮助!
我正在尝试将 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
我该如何解决这个问题?
用于发送电子邮件的命令
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 nor servname provided, or not known
这是因为您的应用程序无法访问您的邮件服务器,有一些原因可能会导致此问题,如未正确配置 SES、错误的电子邮件服务器端点、错误的凭据。
所以你可以按照下面的步骤来弄清楚。
- 配置您的 SES(验证您的 emails/domains)和 get SMTP credentials。所以在这一步你有:
Server Name: email-smtp.<region>.amazonaws.com (e.g: email-smtp.us-west-2.amazonaws.com)
Authentication: Your SMTP credentials.
通过 send testing email 验证您的 SES 配置,按照以下步骤验证您的 SES 配置是否正确。
为您的应用程序设置 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}'
- 在您的应用程序上测试发送电子邮件
当您按照上述步骤操作但仍无法发送电子邮件时,您可能需要仔细检查一些事项:
您的
AWS_SES_ACCESS_KEY_ID
和AWS_SES_SECRET_ACCESS_KEY
应该从您用于执行步骤 2 的 IAM 用户生成。AWS_SES_REGION_ENDPOINT
是这 3 个可用端点之一,与您选择设置 SES 的区域匹配:
US East (N. Virginia): email-smtp.us-east-1.amazonaws.com
US West (Oregon): email-smtp.us-west-2.amazonaws.com
EU (Ireland): email-smtp.eu-west-1.amazonaws.com
希望对您有所帮助!