Cannot assign requested address

1,284 views
Skip to first unread message

youngjin...@gmail.com

unread,
Dec 27, 2007, 7:01:31 PM12/27/07
to Django users
Hello,

While I was following the chapter 7 (Form processing) of the django
book, I got the following error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
site-packages/django/core/handlers/base.py" in get_response
77. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/yjlee/Documents/Worx/Django/DjangoWorx/mysite2/../mysite2/
books/views.py" in contact
30. message, sender, ['admini...@example.com'])
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
site-packages/django/core/mail.py" in send_mail
49. return send_mass_mail([[subject, message, from_email,
recipient_list]], fail_silently, auth_user, auth_password)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
site-packages/django/core/mail.py" in send_mass_mail
66. server = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
smtplib.py" in __init__
244. (code, msg) = self.connect(host, port)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
smtplib.py" in connect
310. raise socket.error, msg

error at /contact/
(49, "Can't assign requested address")

It seems that this error was coming from HttpResponseRedirect() of the
contact view method, but I did not figure what went wrong. This is my
"contact" view method:
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
topic = form.clean_data['topic']
message = form.clean_data['message']
sender = form.clean_data.get('sender', 'nor...@example.com')
send_mail('Feedback from your site, topic: %s' % topic,
message, sender, ['admini...@example.com'])
return HttpResponseRedirect('/contact/thanks/')
else:
form = ContactForm()
return render_to_response('books/contact.html', {'form': form})

One odd thing is that I got the same error (cannot assign requested
address) even if I tried to redirect HttpResponse to "http://
www.google.com".

Can anyone explain how to resolve this problem?

Thanks in advance,

YJ

Alex Koshelev

unread,
Dec 27, 2007, 7:58:33 PM12/27/07
to Django users
Error is in your SMTP parameters in settings.py or something similar.
Look at the traceback:

49. return send_mass_mail([[subject, message, from_email,
> recipient_list]], fail_silently, auth_user, auth_password)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
> site-packages/django/core/mail.py" in send_mass_mail
> 66. server = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
> smtplib.py" in __init__

On 28 дек, 03:01, "youngjin.mich...@gmail.com"
<youngjin.mich...@gmail.com> wrote:
> Hello,
>
> While I was following the chapter 7 (Form processing) of the django
> book, I got the following error:
> Traceback (most recent call last):
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
> site-packages/django/core/handlers/base.py" in get_response
> 77. response = callback(request, *callback_args, **callback_kwargs)
> File "/Users/yjlee/Documents/Worx/Django/DjangoWorx/mysite2/../mysite2/
> books/views.py" in contact
> 30. message, sender, ['administra...@example.com'])
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
> site-packages/django/core/mail.py" in send_mail
> 49. return send_mass_mail([[subject, message, from_email,
> recipient_list]], fail_silently, auth_user, auth_password)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
> site-packages/django/core/mail.py" in send_mass_mail
> 66. server = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
> smtplib.py" in __init__
> 244. (code, msg) = self.connect(host, port)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
> smtplib.py" in connect
> 310. raise socket.error, msg
>
> error at /contact/
> (49, "Can't assign requested address")
>
> It seems that this error was coming from HttpResponseRedirect() of the
> contact view method, but I did not figure what went wrong. This is my
> "contact" view method:
> def contact(request):
> if request.method == 'POST':
> form = ContactForm(request.POST)
> if form.is_valid():
> topic = form.clean_data['topic']
> message = form.clean_data['message']
> sender = form.clean_data.get('sender', 'nore...@example.com')
> send_mail('Feedback from your site, topic: %s' % topic,
> message, sender, ['administra...@example.com'])
> return HttpResponseRedirect('/contact/thanks/')
> else:
> form = ContactForm()
> return render_to_response('books/contact.html', {'form': form})
>
> One odd thing is that I got the same error (cannot assign requested
> address) even if I tried to redirect HttpResponse to "http://www.google.com".

James Bennett

unread,
Dec 27, 2007, 8:18:20 PM12/27/07
to django...@googlegroups.com
On Dec 27, 2007 6:01 PM, youngjin...@gmail.com

<youngjin...@gmail.com> wrote:
> It seems that this error was coming from HttpResponseRedirect() of the
> contact view method, but I did not figure what went wrong.

No, look at the traceback. The lines it's highlighting are the ones
which send the email, and the error message is saying that it wasn't
able to establish a connection with your mail server to send the
email. Double-check the settings you've provided to Django for email
handling and ensure they correctly specify a mail server that you have
access to.


--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

youngjin...@gmail.com

unread,
Dec 28, 2007, 12:05:24 PM12/28/07
to Django users
Thanks for the help.

There was a problem with the mail server. Now I got it working.
Thanks a lot!

On Dec 27, 7:18 pm, "James Bennett" <ubernost...@gmail.com> wrote:
> On Dec 27, 2007 6:01 PM, youngjin.mich...@gmail.com

jamie...@gmail.com

unread,
Jan 11, 2008, 3:35:34 PM1/11/08
to Django users
I think the issue here is actually with send_mail. My guess is that it
can't open a SMTP port to send mail from. I'm trying to track down how
to fix this right now and will update here once I do so.

On Dec 27 2007, 4:01 pm, "youngjin.mich...@gmail.com"
<youngjin.mich...@gmail.com> wrote:
> Hello,
>
> While I was following the chapter 7 (Form processing) of the django
> book, I got the following error:
> Traceback (most recent call last):
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
> site-packages/django/core/handlers/base.py" in get_response
>   77. response = callback(request, *callback_args, **callback_kwargs)
> File "/Users/yjlee/Documents/Worx/Django/DjangoWorx/mysite2/../mysite2/
> books/views.py" in contact
>   30. message, sender, ['administra...@example.com'])
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
> site-packages/django/core/mail.py" in send_mail
>   49. return send_mass_mail([[subject, message, from_email,
> recipient_list]], fail_silently, auth_user, auth_password)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
> site-packages/django/core/mail.py" in send_mass_mail
>   66. server = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
> smtplib.py" in __init__
>   244. (code, msg) = self.connect(host, port)
> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
> smtplib.py" in connect
>   310. raise socket.error, msg
>
>   error at /contact/
>   (49, "Can't assign requested address")
>
> It seems that this error was coming from HttpResponseRedirect() of the
> contact view method, but I did not figure what went wrong. This is my
> "contact" view method:
> def contact(request):
>         if request.method == 'POST':
>                 form = ContactForm(request.POST)
>                 if form.is_valid():
>                         topic = form.clean_data['topic']
>                         message = form.clean_data['message']
>                         sender = form.clean_data.get('sender', 'nore...@example.com')
>                         send_mail('Feedback from your site, topic: %s' % topic,
>                                 message, sender, ['administra...@example.com'])
>                         return HttpResponseRedirect('/contact/thanks/')
>         else:
>                 form = ContactForm()
>         return render_to_response('books/contact.html', {'form': form})
>
> One odd thing is that I got the same error (cannot assign requested
> address) even if I tried to redirect HttpResponse to "http://www.google.com".
Reply all
Reply to author
Forward
0 new messages