text:
Q: 504 Gateway Timeout sending mail I have a problem sending mail from a contact form with Django. I have set smtp config in settings.py and I can send it from local. But in production server, I get a 504 Gateway Timeout Error. This is the Error Log content.
        [Sun Jul 17 18:17:46.142782 2016] [wsgi:error] [pid 16049] [client XXXXX:37298] Timeout when reading response headers from daemon process 'domain.gal': /home/wsgi/web/domain.gal/private/django/domain.gal/domain/wsgi.py, referer: http://domain.gal/contacto/
[Sun Jul 17 18:17:49.120971 2016] [wsgi:error] [pid 16046] Internal Server Error: /contacto/
[Sun Jul 17 18:17:49.121004 2016] [wsgi:error] [pid 16046] Traceback (most recent call last):
[Sun Jul 17 18:17:49.121008 2016] [wsgi:error] [pid 16046]   File "/home/wsgi/web/domain.gal/private/django/env/lib/python3.4/site-packages/django/core/handlers/base.py", line 149, in get_response
[Sun Jul 17 18:17:49.121012 2016] [wsgi:error] [pid 16046]     response = self.process_exception_by_middleware(e, request)
[Sun Jul 17 18:17:49.121015 2016] [wsgi:error] [pid 16046]   File "/home/wsgi/web/domain.gal/private/django/env/lib/python3.4/site-packages/django/core/handlers/base.py", line 147, in get_response
[Sun Jul 17 18:17:49.121018 2016] [wsgi:error] [pid 16046]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Sun Jul 17 18:17:49.121021 2016] [wsgi:error] [pid 16046]   File "/home/wsgi/web/domain.gal/private/django/domain.gal/home/views.py", line 43, in contacto
[Sun Jul 17 18:17:49.121023 2016] [wsgi:error] [pid 16046]     send_mail(subject, message, from_email, ['info@domain.es'])
[Sun Jul 17 18:17:49.121026 2016] [wsgi:error] [pid 16046]   File "/home/wsgi/web/domain.gal/private/django/env/lib/python3.4/site-packages/django/core/mail/__init__.py", line 61, in send_mail
[Sun Jul 17 18:17:49.121029 2016] [wsgi:error] [pid 16046]     return mail.send()
[Sun Jul 17 18:17:49.121032 2016] [wsgi:error] [pid 16046]   File "/home/wsgi/web/domain.gal/private/django/env/lib/python3.4/site-packages/django/core/mail/message.py", line 292, in send
[Sun Jul 17 18:17:49.121034 2016] [wsgi:error] [pid 16046]     return self.get_connection(fail_silently).send_messages([self])
[Sun Jul 17 18:17:49.121037 2016] [wsgi:error] [pid 16046]   File "/home/wsgi/web/domain.gal/private/django/env/lib/python3.4/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
[Sun Jul 17 18:17:49.121040 2016] [wsgi:error] [pid 16046]     new_conn_created = self.open()
[Sun Jul 17 18:17:49.121043 2016] [wsgi:error] [pid 16046]   File "/home/wsgi/web/domain.gal/private/django/env/lib/python3.4/site-packages/django/core/mail/backends/smtp.py", line 58, in open
[Sun Jul 17 18:17:49.121060 2016] [wsgi:error] [pid 16046]     self.connection = connection_class(self.host, self.port, **connection_params)
[Sun Jul 17 18:17:49.121063 2016] [wsgi:error] [pid 16046]   File "/usr/lib64/python3.4/smtplib.py", line 242, in __init__
[Sun Jul 17 18:17:49.121066 2016] [wsgi:error] [pid 16046]     (code, msg) = self.connect(host, port)
[Sun Jul 17 18:17:49.121069 2016] [wsgi:error] [pid 16046]   File "/usr/lib64/python3.4/smtplib.py", line 321, in connect
[Sun Jul 17 18:17:49.121071 2016] [wsgi:error] [pid 16046]     self.sock = self._get_socket(host, port, self.timeout)
[Sun Jul 17 18:17:49.121074 2016] [wsgi:error] [pid 16046]   File "/usr/lib64/python3.4/smtplib.py", line 292, in _get_socket
[Sun Jul 17 18:17:49.121076 2016] [wsgi:error] [pid 16046]     self.source_address)
[Sun Jul 17 18:17:49.121079 2016] [wsgi:error] [pid 16046]   File "/usr/lib64/python3.4/socket.py", line 512, in create_connection
[Sun Jul 17 18:17:49.121081 2016] [wsgi:error] [pid 16046]     raise err
[Sun Jul 17 18:17:49.121084 2016] [wsgi:error] [pid 16046]   File "/usr/lib64/python3.4/socket.py", line 503, in create_connection
[Sun Jul 17 18:17:49.121086 2016] [wsgi:error] [pid 16046]     sock.connect(sa)
[Sun Jul 17 18:17:49.121091 2016] [wsgi:error] [pid 16046] TimeoutError: [Errno 110] Connection timed out
[Sun Jul 17 18:17:49.121097 2016] [wsgi:error] [pid 16046]

Any idea plz?

A: Your app can't connect to the specified SMTP server. Check for the following issues:

*

*Is your SMTP details correct?

*Do you have a running SMTP server at the configured host/port?

*Is the connection being blocked by a firewall?

From the log, it's evident that the SMTP connection is timing out. Please provide more details (code/configuration) to speculate better.

A: Ok masnum is right. I have changed the port and dissabled TLS use and it works. But I have two questions. My configuration was the follow:
EMAIL_PORT = 587
EMAIL_USE_TLS = True

Is this correct? I can use this in localhost, why not in production server? Busy port maybe?
And the other question. I use this:
try:
            send_mail(subject, message, from_email, ['info@domain.com'])
        except BadHeaderError:
            messages.warning(request, 'Ha ocurrido un fallo. Inténtelo de nuevo más tarde.')
            return render(request, "contacto.html", {'form': form})

        except TimeoutError:
            messages.warning(request, 'Ha ocurrido un fallo. Inténtelo de nuevo más tarde.')
            return render(request, "contacto.html", {'form': form})

Why the error is not catched by TimeoutError instead of 504 Apache?
Txh


text:
Q: How can I print the name of the object / interface with Xcode breakpoint log? Xcode debug log can print the method name using %B and the hit count using %H. How can I print the interface / object  name using similar notation ? Preferably without the use of NSLog / debugger command.

A: The closest you can get is
NSLog("My file is %@", [NSString stringWithUTF8String:__FILE__]);

__PRETTY_FUNCTION__ contains the class name and method, which may suit you better than FILE.

A: I just found that @[self class]@ log message will do the trick. I am not sure its validity on every occasion. I am using @[self class]@ %B %H for my purpose. I also found this question and answer but it was not just working on Xcode 6.2.

A: Every Objective-C object can be printed with %@. NSLog(@"%@", someObject) will print object's description. You can override description method for your classes to provide more detailed info. Look at this note too: Improved logging in Objective-C

A: In the breakpoint's debugger command action, you can put:
expr printf ("[%s %s]\n", (char *)object_getClassName(self), _cmd)

This will output, e.g.  [SomeClass someMethod:]

A: You can print anything using NSLog();
Say, for example, you have an
NSString *myString = @"qdfsqsdfqsdf";

This is an important string you would like to log, you'll just type :
NSLog(@"My important string : %@", myString);

If that is what you're asking, I'm surprised you dont' know that if you already know about %B & %H.  Am I answering your question or do you need a bit more?

redpajama_set_name: RedPajamaStackExchange