Thursday, January 8, 2015

Re: I can send mail with shell but can't sent mail via view


gaierror at /userforget/

[Errno -3] Temporary failure in name resolution

Request Method: POST
Request URL: http://10.252.84.159/userforget/
Django Version: 1.6.8
Exception Type: gaierror
Exception Value:

[Errno -3] Temporary failure in name resolution

Exception Location: /usr/lib64/python2.6/socket.py in create_connection, line 553
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path:

['/usr/lib64/python26.zip',
'/usr/lib64/python2.6',
'/usr/lib64/python2.6/plat-linux2',
'/usr/lib64/python2.6/lib-tk',
'/usr/lib64/python2.6/lib-old',
'/usr/lib64/python2.6/lib-dynload',
'/usr/lib64/python2.6/site-packages',
'/usr/lib64/python2.6/site-packages/PIL',
'/usr/lib/python2.6/site-packages',
'/var/www/html/psp/psp']

Server time: Thu, 8 Jan 2015 11:19:15 +0330
Traceback Switch back to interactive view
Environment: Request Method: POST Request URL: http://10.252.84.159/userforget/ Django Version: 1.6.8 Python Version: 2.6.6 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'captcha', 'qatardb', 'oauthapp', 'provider', 'provider.oauth2', 'tastypie', 'pspauth') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'corsheaders.middleware.CorsMiddleware') Traceback: File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response 112. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/var/www/html/psp/psp/view.py" in userforget 697. a = send_mail('test', 'hello', 'h.rashnoo@pep.co.ir', ['mhr1224@gmail.com']) File "/usr/lib/python2.6/site-packages/django/core/mail/__init__.py" in send_mail 50. connection=connection).send() File "/usr/lib/python2.6/site-packages/django/core/mail/message.py" in send 276. return self.get_connection(fail_silently).send_messages([self]) File "/usr/lib/python2.6/site-packages/django/core/mail/backends/smtp.py" in send_messages 87. new_conn_created = self.open() File "/usr/lib/python2.6/site-packages/django/core/mail/backends/smtp.py" in open 48. local_hostname=DNS_NAME.get_fqdn()) File "/usr/lib64/python2.6/smtplib.py" in __init__ 239. (code, msg) = self.connect(host, port) File "/usr/lib64/python2.6/smtplib.py" in connect 295. self.sock = self._get_socket(host, port, self.timeout) File "/usr/lib64/python2.6/smtplib.py" in _get_socket 273. return socket.create_connection((port, host), timeout) File "/usr/lib64/python2.6/socket.py" in create_connection 553. for res in getaddrinfo(host, port, 0, SOCK_STREAM): Exception Type: gaierror at /userforget/ Exception Value: [Errno -3] Temporary failure in name resolution

Request information
GET

No GET data
POST
Variable Value
username

u'fgf'

FILES

No FILES data
COOKIES
Variable Value
csrftoken

'GMu3mYlYIU4sgJervyKUYVOEpwIjoV3X'

sessionid

'35a1kpexgig7mjuyr4pycr85md5evoex'

META
Variable Value
mod_wsgi.listener_port

'80'

HTTP_COOKIE

'sessionid=35a1kpexgig7mjuyr4pycr85md5evoex; csrftoken=GMu3mYlYIU4sgJervyKUYVOEpwIjoV3X'

mod_wsgi.listener_host

''

SERVER_SOFTWARE

'Apache/2.2.15 (CentOS)'

SCRIPT_NAME

u''

mod_ssl.var_lookup

''

mod_wsgi.handler_script

''

SERVER_SIGNATURE

'<address>Apache/2.2.15 (CentOS) Server at 10.252.84.159 Port 80</address>\n'

REQUEST_METHOD

'POST'

PATH_INFO

u'/userforget/'

SERVER_PROTOCOL

'HTTP/1.1'

QUERY_STRING

''

CONTENT_LENGTH

'12'

HTTP_USER_AGENT

'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0'

HTTP_CONNECTION

'keep-alive'

HTTP_REFERER

'http://10.252.84.159/user/'

SERVER_NAME

'10.252.84.159'

REMOTE_ADDR

'10.252.14.137'

mod_wsgi.request_handler

'wsgi-script'

wsgi.url_scheme

'http'

PATH_TRANSLATED

'/var/www/html/psp/psp/django.wsgi/userforget/'

SERVER_PORT

'80'

wsgi.multiprocess

True

mod_wsgi.input_chunked

'0'

SERVER_ADDR

'10.252.84.159'

DOCUMENT_ROOT

'/var/www/html'

mod_wsgi.process_group

''

SCRIPT_FILENAME

'/var/www/html/psp/psp/django.wsgi'

SERVER_ADMIN

'root@localhost'

wsgi.input

<mod_wsgi.Input object at 0x7f0ff8055bb0>

HTTP_HOST

'10.252.84.159'

mod_ssl.is_https

0

wsgi.multithread

False

mod_wsgi.callable_object

'application'

REQUEST_URI

'/userforget/'

HTTP_ACCEPT

'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'

wsgi.version

(1, 1)

GATEWAY_INTERFACE

'CGI/1.1'

wsgi.run_once

False

wsgi.errors

<mod_wsgi.Log object at 0x7f0ff8143b30>

REMOTE_PORT

'40094'

HTTP_ACCEPT_LANGUAGE

'en-US,en;q=0.5'

mod_wsgi.version

(3, 2)

CONTENT_TYPE

'application/x-www-form-urlencoded'

mod_wsgi.application_group

'rashno.dev.local|'

mod_wsgi.script_reloading

'1'

wsgi.file_wrapper

''

HTTP_ACCEPT_ENCODING

'gzip, deflate'

Settings
Using settings module settings
Setting Value
USE_L10N

True

USE_THOUSAND_SEPARATOR

False

CSRF_COOKIE_SECURE

False

LANGUAGE_CODE

'en-us'

ROOT_URLCONF

'urls'

MANAGERS

()

BASE_DIR

'/var/www/html/psp'

DEFAULT_CHARSET

'utf-8'

SESSION_SERIALIZER

'django.contrib.sessions.serializers.JSONSerializer'

STATIC_ROOT

None

ALLOWED_HOSTS

['*']

MESSAGE_STORAGE

'django.contrib.messages.storage.fallback.FallbackStorage'

EMAIL_SUBJECT_PREFIX

'[Django] '

FILE_UPLOAD_PERMISSIONS

None

STATICFILES_FINDERS

('django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder')

SESSION_CACHE_ALIAS

'default'

SESSION_COOKIE_DOMAIN

None

SESSION_COOKIE_NAME

'sessionid'

ADMIN_FOR

()

TIME_INPUT_FORMATS

('%H:%M:%S', '%H:%M:%S.%f', '%H:%M')

DATABASES

{'default': {'ATOMIC_REQUESTS': False,
'AUTOCOMMIT': True,
'CONN_MAX_AGE': 0,
'ENGINE': 'django.db.backends.sqlite3',
'HOST': '',
'NAME': '/var/www/html/psp/psp/db.sqlite3',
'OPTIONS': {},
'PASSWORD': u'********************',
'PORT': '',
'TEST_CHARSET': None,
'TEST_COLLATION': None,
'TEST_MIRROR': None,
'TEST_NAME': None,
'TIME_ZONE': 'UTC',
'USER': ''}}

SERVER_EMAIL

'mail.pep.co.ir'

FILE_UPLOAD_HANDLERS

('django.core.files.uploadhandler.MemoryFileUploadHandler',
'django.core.files.uploadhandler.TemporaryFileUploadHandler')

DEFAULT_CONTENT_TYPE

'text/html'

APPEND_SLASH

True

FIRST_DAY_OF_WEEK

0

DATABASE_ROUTERS

[]

YEAR_MONTH_FORMAT

'F Y'

STATICFILES_STORAGE

'django.contrib.staticfiles.storage.StaticFilesStorage'

CACHES

{'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}

SESSION_COOKIE_PATH

'/'

MIDDLEWARE_CLASSES

('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware')

USE_I18N

True

THOUSAND_SEPARATOR

','

SECRET_KEY

u'********************'

LANGUAGE_COOKIE_NAME

'django_language'

DEFAULT_INDEX_TABLESPACE

''

TRANSACTIONS_MANAGED

False

LOGGING_CONFIG

'django.utils.log.dictConfig'

SEND_BROKEN_LINK_EMAILS

False

TEMPLATE_LOADERS

('django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader')

WSGI_APPLICATION

'psp.wsgi.application'

TEMPLATE_DEBUG

True

X_FRAME_OPTIONS

'SAMEORIGIN'

CSRF_COOKIE_NAME

'csrftoken'

FORCE_SCRIPT_NAME

None

USE_X_FORWARDED_HOST

False

SIGNING_BACKEND

'django.core.signing.TimestampSigner'

SESSION_COOKIE_SECURE

False

CSRF_COOKIE_DOMAIN

None

FILE_CHARSET

'utf-8'

DEBUG

True

SESSION_FILE_PATH

None

DEFAULT_FILE_STORAGE

'django.core.files.storage.FileSystemStorage'

INSTALLED_APPS

('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'captcha',
'qatardb',
'oauthapp',
'provider',
'provider.oauth2',
'tastypie',
'pspauth')

LANGUAGES

(('af', 'Afrikaans'),
('ar', 'Arabic'),
('az', 'Azerbaijani'),
('bg', 'Bulgarian'),
('be', 'Belarusian'),
('bn', 'Bengali'),
('br', 'Breton'),
('bs', 'Bosnian'),
('ca', 'Catalan'),
('cs', 'Czech'),
('cy', 'Welsh'),
('da', 'Danish'),
('de', 'German'),
('el', 'Greek'),
('en', 'English'),
('en-gb', 'British English'),
('eo', 'Esperanto'),
('es', 'Spanish'),
('es-ar', 'Argentinian Spanish'),
('es-mx', 'Mexican Spanish'),
('es-ni', 'Nicaraguan Spanish'),
('es-ve', 'Venezuelan Spanish'),
('et', 'Estonian'),
('eu', 'Basque'),
('fa', 'Persian'),
('fi', 'Finnish'),
('fr', 'French'),
('fy-nl', 'Frisian'),
('ga', 'Irish'),
('gl', 'Galician'),
('he', 'Hebrew'),
('hi', 'Hindi'),
('hr', 'Croatian'),
('hu', 'Hungarian'),
('ia', 'Interlingua'),
('id', 'Indonesian'),
('is', 'Icelandic'),
('it', 'Italian'),
('ja', 'Japanese'),
('ka', 'Georgian'),
('kk', 'Kazakh'),
('km', 'Khmer'),
('kn', 'Kannada'),
('ko', 'Korean'),
('lb', 'Luxembourgish'),
('lt', 'Lithuanian'),
('lv', 'Latvian'),
('mk', 'Macedonian'),
('ml', 'Malayalam'),
('mn', 'Mongolian'),
('my', 'Burmese'),
('nb', 'Norwegian Bokmal'),
('ne', 'Nepali'),
('nl', 'Dutch'),
('nn', 'Norwegian Nynorsk'),
('os', 'Ossetic'),
('pa', 'Punjabi'),
('pl', 'Polish'),
('pt', 'Portuguese'),
('pt-br', 'Brazilian Portuguese'),
('ro', 'Romanian'),
('ru', 'Russian'),
('sk', 'Slovak'),
('sl', 'Slovenian'),
('sq', 'Albanian'),
('sr', 'Serbian'),
('sr-latn', 'Serbian Latin'),
('sv', 'Swedish'),
('sw', 'Swahili'),
('ta', 'Tamil'),
('te', 'Telugu'),
('th', 'Thai'),
('tr', 'Turkish'),
('tt', 'Tatar'),
('udm', 'Udmurt'),
('uk', 'Ukrainian'),
('ur', 'Urdu'),
('vi', 'Vietnamese'),
('zh-cn', 'Simplified Chinese'),
('zh-tw', 'Traditional Chinese'))

COMMENTS_ALLOW_PROFANITIES

False

STATICFILES_DIRS

()

PREPEND_WWW

False

SECURE_PROXY_SSL_HEADER

None

SESSION_COOKIE_HTTPONLY

True

DEBUG_PROPAGATE_EXCEPTIONS

False

MONTH_DAY_FORMAT

'F j'

LOGIN_URL

'/accounts/login/'

SESSION_EXPIRE_AT_BROWSER_CLOSE

False

TIME_FORMAT

'P'

AUTH_USER_MODEL

'auth.User'

DATE_INPUT_FORMATS

('%Y-%m-%d',
'%m/%d/%Y',
'%m/%d/%y',
'%b %d %Y',
'%b %d, %Y',
'%d %b %Y',
'%d %b, %Y',
'%B %d %Y',
'%B %d, %Y',
'%d %B %Y',
'%d %B, %Y')

AUTHENTICATION_BACKENDS

('django.contrib.auth.backends.ModelBackend',)

EMAIL_HOST_PASSWORD

u'********************'

PASSWORD_RESET_TIMEOUT_DAYS

u'********************'

CACHE_MIDDLEWARE_ALIAS

'default'

SESSION_SAVE_EVERY_REQUEST

False

NUMBER_GROUPING

0

SESSION_ENGINE

'django.contrib.sessions.backends.db'

CSRF_FAILURE_VIEW

'django.views.csrf.csrf_failure'

CSRF_COOKIE_PATH

'/'

LOGIN_REDIRECT_URL

'/accounts/profile/'

DECIMAL_SEPARATOR

'.'

IGNORABLE_404_URLS

()

LOCALE_PATHS

()

TEMPLATE_STRING_IF_INVALID

''

LOGOUT_URL

'/accounts/logout/'

EMAIL_USE_TLS

True

FIXTURE_DIRS

()

EMAIL_HOST

'mail.pep.co.ir'

DATE_FORMAT

'N j, Y'

MEDIA_ROOT

''

DEFAULT_EXCEPTION_REPORTER_FILTER

'django.views.debug.SafeExceptionReporterFilter'

ADMINS

()

FORMAT_MODULE_PATH

None

DEFAULT_FROM_EMAIL

'h.rashnoo@pep.co.ir'

MEDIA_URL

''

DATETIME_FORMAT

'N j, Y, P'

TEMPLATE_DIRS

('/var/www/html/psp/psp/temples',)

DISALLOWED_USER_AGENTS

()

ALLOWED_INCLUDE_ROOTS

()

LOGGING

{}

SHORT_DATE_FORMAT

'm/d/Y'

TEST_RUNNER

'django.test.runner.DiscoverRunner'

CACHE_MIDDLEWARE_KEY_PREFIX

u'********************'

TIME_ZONE

'Asia/Tehran'

SOUTH_MIGRATION_MODULES

{'captcha': 'captcha.south_migrations'}

FILE_UPLOAD_MAX_MEMORY_SIZE

2621440

EMAIL_BACKEND

'django.core.mail.backends.smtp.EmailBackend'

DEFAULT_TABLESPACE

''

TEMPLATE_CONTEXT_PROCESSORS

('django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.contrib.messages.context_processors.messages')

SESSION_COOKIE_AGE

1209600

SETTINGS_MODULE

'settings'

USE_ETAGS

False

LANGUAGES_BIDI

('he', 'ar', 'fa', 'ur')

FILE_UPLOAD_TEMP_DIR

None

INTERNAL_IPS

()

STATIC_URL

'/static/'

EMAIL_PORT

25

USE_TZ

True

SHORT_DATETIME_FORMAT

'm/d/Y P'

PASSWORD_HASHERS

u'********************'

ABSOLUTE_URL_OVERRIDES

{}

CACHE_MIDDLEWARE_SECONDS

600

CSRF_COOKIE_HTTPONLY

False

DATETIME_INPUT_FORMATS

('%Y-%m-%d %H:%M:%S',
'%Y-%m-%d %H:%M:%S.%f',
'%Y-%m-%d %H:%M',
'%Y-%m-%d',
'%m/%d/%Y %H:%M:%S',
'%m/%d/%Y %H:%M:%S.%f',
'%m/%d/%Y %H:%M',
'%m/%d/%Y',
'%m/%d/%y %H:%M:%S',
'%m/%d/%y %H:%M:%S.%f',
'%m/%d/%y %H:%M',
'%m/%d/%y')

EMAIL_HOST_USER

'h.rashnoo@pep.co.ir'

PROFANITIES_LIST

u'********************'

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 500 page.
Thank you for your reply, it seems that every thing is ok:
$ nslookup mail.pep.co.ir

Server:         10.252.84.50
Address:        10.252.84.50#53

Non-authoritative answer:
Name:   mail.pep.co.ir
Address: 79.175.161.174


and:

$ python manage.py shell

>>> import socket
>>> socket.gethostbyname("mail.pep.co.ir")
'79.175.161.174'

I attach the whole traceback with this reply.thank you.


On Thursday, January 8, 2015 12:08:26 PM UTC+3:30, James Schneider wrote:
Can you send the whole traceback?

Name resolution errors indicate an issue with DNS reachability, or a domain name incorrectly entered somewhere. I'm assuming that you are running the shell on the same server that is running your Django instance? You should be able to do the following on the server where Django is running:

$ python manage.py shell
>>> import socket
>>> # checks if name resolution is working at all
>>> socket.gethostbyname('www.google.com')
'74.125.20.105'
>>> # note you may get a different IP address
>>>
>>> # check if your email host value is resolvable
>>> socket.gethostbyname("mail.xxxxxx.ir")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
gaierror: [Errno -5] No address associated with hostname
>>> 

Obviously I received an error here since I used the masked value you provided. You should get an IPv4/IPv6 address back, or an error similar to the one you posted.

You can also do a quick check if you have shell or command prompt access available on your server outside of Python:

$ nslookup www.google.com
Server: 127.0.1.1
Address: 127.0.1.1#53

Non-authoritative answer:
Address: 74.125.239.112
Address: 74.125.239.114
Address: 74.125.239.113
Address: 74.125.239.116
Address: 74.125.239.115

$ nslookup mail.xxxxxx.ir
Server: 127.0.1.1
Address: 127.0.1.1#53

** server can't find mail.xxxxxx.ir: NXDOMAIN

An NXDOMAIN response means that the domain is either typed incorrectly, or just doesn't exist out on the wild Internet (or wherever your DNS server recursively looks for you)

That command should work on Windows and most Linux distributions (some Linux systems include the 'host' command as an alternative if BIND tools are installed). The output may be formatted differently but should provide similar information.

The full traceback for the error will likely be most helpful, though.


-James

On Thu, Jan 8, 2015 at 12:08 AM, Hossein Rashnoo <mhr...@gmail.com> wrote:
Hi
I use this settings to send email:

settings.py
EMAIL_HOST = "mail.xxxxxx.ir"
EMAIL_PORT = "25"
EMAIL_HOST_USER = "xx...@xxx.ir"
EMAIL_HOST_PASSWORD = "xxxxxxxx"
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL  = 'xx...@xxx.ir'

and in python shell:
from django.core.mail import send_mail
send_mail('test', 'hello', 'xx...@xxx.ir', ['myE...@gmail.com'])

And its successfully sent But when i use that two line code in view, i got this error:

gaierror at /userforget/

[Errno -3] Temporary failure in name resolution

Please help me.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6aaaeaac-dc68-477a-b2d7-7b2821097c36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c3f6d078-c5d7-48f2-812a-9c078ac50a34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment