Bug #115418 python mysql connector 8.3.0 raise %-.100s:%u when input a wrong host
Submitted: 24 Jun 12:38 Modified: 13 Sep 18:39
Reporter: sakurai hiro Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:8.3.0, 8.4.0 OS:Debian (8)
Assigned to: CPU Architecture:x86
Tags: Python Connector

[24 Jun 12:38] sakurai hiro
Description:
When I use the wrong host "foo.host" on python MySQL connector to connect mysql, I expect to receive the exception like "mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'foo.host:3306' (-2 Name or service not known)". 
However, in version 8.3.0, when this exception is raised, the exception text is formatted incorrectly, leading to another exception being thrown: "mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '%-.100s:%u' (%s) (Warning: %u format: a real number is required, not str)".
By reading the source code, I found that in mysql/connector/network.py:748, the exception is raised with incorrect parameter count. It should be like line 760, where it is "values=(self.server_host,self.server_port,_strioerror(err))". Although this bug is not very serious, it happened to obscure the host information that I wanted to obtain.

How to repeat:
import mysql.connector
mysql.connector.connect(**{
    'passwd': 'something', 
    'host': '',
    'db': 'something', 
    'user': 'something', 
    'autocommit': True,
    'use_unicode': False,
    'charset': 'latin1',
    'use_pure': True,
})

just run on different version of python mysql connector.

Suggested fix:
origin source code in 8.3.0
mysql/connector/network.py:748~750
748             raise InterfaceError(
749                 errno=2003, values=(self.address, _strioerror(err))
750             ) from err

fixed code maybe:
760             raise InterfaceError(
761                 errno=2003,
762                 values=(
763                     self.server_host,
764                     self.server_port,
765                     _strioerror(err),
766                 ),
767             ) from err
[24 Jun 14:07] MySQL Verification Team
Hello sakurai hiro,

Thank you for the report and feedback.

regards,
Umesh
[13 Sep 18:39] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/Python 9.1.0 release, and here's the proposed changelog entry from the documentation team:

An unformatted error message was emitted for an unreachable host when
using the pure Python implementation.

Thank you for the bug report.