I have written a interface for a myqsl database, which in case of when an error arises, like as if the database was offline, it handles it by raising my custom error so that i know whats wrong. I was pleased with it and decided it was ready to be converted to exe, and did this using py2exe. this failed, and after some research i find out that it doesnt work anymore so i downgraded to python 3.4. Now it converts but the converted program doesnt handle errors anymore.
I have checked if i have the correct mysql connector, and redownloaded the exact same one, so that it would be included as the error I am handling is usually the mysql.connector.Error.
Error handling in original program:
import myqsl.connector as mariadb
try:
mariadb_connection = mariadb.connect(user='root', password='', database='marsmenagerie')
cursor = mariadb_connection.cursor()
except mariadb.Error:
clearscreen()
print("Failed to connect to Database. (Error: 2475JWRT), Contact Censored")
print("===========================")
PAUSE()
exit()
Error the converted program creates if this error should be raised:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\mysql\connector\network.py", line 525, in open_connection
self.sock.connect(sockaddr)
ConnectionRefusedError: [WinError 10061] Kan geen verbinding maken omdat de doelcomputer de verbinding actief heeft geweigerd
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\mysql\connector\locales\__init__.py", line 56, in get_client_error
globals(), locals(), ['client_error'])
ImportError: No module named 'mysql.connector.locales.eng'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 245, in _open_connection
self._socket.open_connection()
File "C:\Python34\lib\site-packages\mysql\connector\network.py", line 528, in open_connection
errno=2003, values=(self.get_address(), _strioerror(err)))
File "C:\Python34\lib\site-packages\mysql\connector\errors.py", line 187, in __init__
self.msg = get_client_error(self.errno)
File "C:\Python34\lib\site-packages\mysql\connector\locales\__init__.py", line 59, in get_client_error
language))
ImportError: No localization support for language 'eng'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\mysql\connector\network.py", line 148, in send_plain
self.sock.sendall(packet)
OSError: [WinError 10057] Een aanvraag om gegevens te verzenden of te ontvangen is niet toegestaan omdat de socket niet is verbonden en omdat (tijdens het verzenden op een datagramsocket via een sendto-aanroep) geen adres is opgegeven
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\mysql\connector\locales\__init__.py", line 56, in get_client_error
globals(), locals(), ['client_error'])
ImportError: No module named 'mysql.connector.locales.eng'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 102, in __init__
self.connect(**kwargs)
File "C:\Python34\lib\site-packages\mysql\connector\abstracts.py", line 731, in connect
self._open_connection()
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 256, in _open_connection
self.close()
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 276, in close
self.cmd_quit()
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 617, in cmd_quit
self._socket.send(packet, 0, 0)
File "C:\Python34\lib\site-packages\mysql\connector\network.py", line 151, in send_plain
errno=2055, values=(self.get_address(), _strioerror(err)))
File "C:\Python34\lib\site-packages\mysql\connector\errors.py", line 187, in __init__
self.msg = get_client_error(self.errno)
File "C:\Python34\lib\site-packages\mysql\connector\locales\__init__.py", line 59, in get_client_error
language))
ImportError: No localization support for language 'eng'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\mysql\connector\network.py", line 148, in send_plain
self.sock.sendall(packet)
OSError: [WinError 10057] Een aanvraag om gegevens te verzenden of te ontvangen is niet toegestaan omdat de socket niet is verbonden en omdat (tijdens het verzenden op een datagramsocket via een sendto-aanroep) geen adres is opgegeven
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\mysql\connector\locales\__init__.py", line 56, in get_client_error
globals(), locals(), ['client_error'])
ImportError: No module named 'mysql.connector.locales.eng'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "program.py", line 16, in <module>
File "C:\Python34\lib\site-packages\mysql\connector\__init__.py", line 173, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 105, in __init__
self.close()
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 276, in close
self.cmd_quit()
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 617, in cmd_quit
self._socket.send(packet, 0, 0)
File "C:\Python34\lib\site-packages\mysql\connector\network.py", line 151, in send_plain
errno=2055, values=(self.get_address(), _strioerror(err)))
File "C:\Python34\lib\site-packages\mysql\connector\errors.py", line 187, in __init__
self.msg = get_client_error(self.errno)
File "C:\Python34\lib\site-packages\mysql\connector\locales\__init__.py", line 59, in get_client_error
language))
ImportError: No localization support for language 'eng'
I know, its long. And i am trying to keep it as short as possible, but I dont want to withhold information which might be relevant. Perhaps my biggest problem with making a MCVE.
I expected it to raise the error I coded in. However it just raises the error shown above. When run with the database active the program runs fine.
Well. I have solved it! The problem is that the eng localization for the standard mysql errors isnt copied over by py2exe, atleast not in this case. You can find the evidence for this in this line in the error:
ImportError: No module named 'mysql.connector.locales.eng'
This problem appeared to have existed before and thus there was a fix. (ImportError: No localization support for language 'eng' in python) I manually added the eng localization to the library.zip file with some help from this site: http://pydoc.net/mysql-connector-python/2.0.2/
And it is now working like a dream.