Opened 8 years ago

Closed 8 years ago

#27771 closed Cleanup/optimization (wontfix)

Problem with unicode literals and EMAIL_PORT

Reported by: Michal Čihař Owned by: nobody
Component: Core (Mail) Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When your settings.py looks like:

from __future__ import unicode_literals
EMAIL_HOST= 'localhost'
EMAIL_PORT = '587'

You end up with error when sending mail:

File "/opt/weblate/.local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py" in open
  58.             self.connection = connection_class(self.host, self.port, **connection_params)

File "/usr/lib/python2.7/smtplib.py" in __init__
  256.             (code, msg) = self.connect(host, port)

File "/usr/lib/python2.7/smtplib.py" in connect
  316.         self.sock = self._get_socket(host, port, self.timeout)

File "/usr/lib/python2.7/smtplib.py" in _get_socket
  291.         return socket.create_connection((host, port), timeout)

File "/usr/lib/python2.7/socket.py" in create_connection
  553.     for res in getaddrinfo(host, port, 0, SOCK_STREAM):

Exception Type: error at /accounts/register/
Exception Value: getaddrinfo() argument 2 must be integer or string

This is caused by fact that that getaddrinfo happily accepts int or string, but not unicode literals as port (it doesn't have problem with unicode literals as hostname though):

>>> from __future__ import unicode_literals
>>> import socket
>>> socket.getaddrinfo('localhost', '567', 0, socket.SOCK_STREAM)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.error: getaddrinfo() argument 2 must be integer or string

I think Django should prevent this configuration error, or at least properly tell where the problem is.

Originally reported at https://github.com/WeblateOrg/weblate/issues/1330

Change History (1)

comment:1 by Tim Graham, 8 years ago

Component: Core (Other)Core (Mail)
Resolution: wontfix
Status: newclosed
Type: UncategorizedCleanup/optimization

Python 2 specific issues are now obsolete as Django 1.11 will be the last version to support it and master now targets Django 2.0.

Note: See TracTickets for help on using tickets.
Back to Top