gpt4 book ai didi

python - gaierror [Errno 8] 当使用 Django python 和 gmail 发送邮件时

转载 作者:太空狗 更新时间:2023-10-29 20:54:04 25 4
gpt4 key购买 nike

我是 Django 和 Python 的新手。我正在学习本教程 "Try Django 16"我不明白它的工作。我添加了 fail_silent=false 来获取错误。

[Errno 8] nodename nor servname provided, or not known

有没有人可以帮我找到这个问题?

gaierror at /thank-you/
[Errno 8] nodename nor servname provided, or not known
Request Method: POST
Request URL: http://127.0.0.1:8000/thank-you/
Django Version: 1.6.5
Exception Type: gaierror
Exception Value:
[Errno 8] nodename nor servname provided, or not known
Exception Location: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py in create_connection, line 553
Python Executable: /usr/bin/python
Python Version: 2.7.5
Python Path:
['/Users/andremensink/Desktop/skillshare/src',
'/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
'/Library/Python/2.7/site-packages']
Server time: Sat, 28 Jun 2014 13:23:10 +0000




Environment:


Request Method: POST
Request URL: http://127.0.0.1:8000/thank-you/

Django Version: 1.6.5
Python Version: 2.7.5
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
'signups')
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 "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
112. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/andremensink/Desktop/skillshare/src/signups/views.py" in thankyou
40. send_mail(subject,message,from_email,to_list,fail_silently=False)
File "/Library/Python/2.7/site-packages/django/core/mail/__init__.py" in send_mail
50. connection=connection).send()
File "/Library/Python/2.7/site-packages/django/core/mail/message.py" in send
274. return self.get_connection(fail_silently).send_messages([self])
File "/Library/Python/2.7/site-packages/django/core/mail/backends/smtp.py" in send_messages
87. new_conn_created = self.open()
File "/Library/Python/2.7/site-packages/django/core/mail/backends/smtp.py" in open
48. local_hostname=DNS_NAME.get_fqdn())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py" in __init__
250. (code, msg) = self.connect(host, port)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py" in connect
310. self.sock = self._get_socket(host, port, self.timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py" in _get_socket
285. return socket.create_connection((host, port), timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py" in create_connection
553. for res in getaddrinfo(host, port, 0, SOCK_STREAM):

Exception Type: gaierror at /thank-you/
Exception Value: [Errno 8] nodename nor servname provided, or not known

python中的代码是:

#--django stuff
from django.conf import settings
from django.contrib import messages
from django.core.mail import send_mail #EmailMessage#send_mail
from django.shortcuts import render, render_to_response, RequestContext, HttpResponsePermanentRedirect

subject = 'This is the subject'
message = 'Welcome to the list and enjoy your product.\n This is the message.'
from_email = settings.EMAIL_HOST_USER
to_list = [save_it.email,settings.EMAIL_HOST_USER]
send_mail(subject,message,from_email,to_list,fail_silently=False)

在设置中定义:

#for gmail or google apps
EMAIL_USE_TLS = True
EMAIL_HOST = 'smpt.gmail.com'
EMAIL_HOST_USER = 'mymail@gmail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
ACCOUNT_EMAIL_VERIFICATION = 'none'

最佳答案

EMAIL_HOST = 'smpt.gmail.com'

什么是smpt?

should be EMAIL_HOST = 'smtp.gmail.com'

http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol

关于python - gaierror [Errno 8] 当使用 Django python 和 gmail 发送邮件时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24465277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com