2

Update: This seems to be connected specifically to the an issue with pyinstaller freezing the socket package. Running the following code is fine in python, but after freezing to an exe with pyinstaller it gives the OSError.

import socket

try:
    socket.socket()
except OSError as e:
    print(e)

Original text:

I'm currently trying to build a python script that queries a mySQL database using mysql.connector. Running the code in python works fine, but when I freeze it using pyinstaller and run the exe I get an OSError: [WinError 10022] An invalid argument was supplied when it tries to run the mysql.connector.connect function.

My code is below:

import mysql.connector

def test(user, password, ip, query):
    con = mysql.connector.connect(user=user,
                              password=password,
                              host=ip)

    cursor = con.cursor()
    cursor.execute(query)
    rows = cursor.fetchall()

    cursor.close()
    con.close()

    return rows

The full error text is:

Traceback (most recent call last):
    File "site-packages\mysql\connector\network.py", line 507, in open_connection
    File "socket.py", line 134 in __init__
OSError: [WinError 10022] An invalid argument was supplied

Looking around, the only mysql.connector questions related to pyinstaller I can find are due to import errors while the WinError 10022 questions seem to be about other packages.

  • Are you able to connect to the mysql server with those credentials? Might be that the socket is busy – Dhruv Aggarwal Aug 12 '17 at 13:10
  • Yup, I can always connect when I do it in python directly, it is only when trying the exe that the error occurs. – Further_Reading Aug 12 '17 at 14:21
  • Just updated the text as I discovered that the root cause seems to be the `socket` package that `mysql.connector` was using. Looks like it might always throw that error when creating a new socket class in a pyinstaller frozen exe. – Further_Reading Aug 12 '17 at 14:30
  • Maybe PyInstaller does not recognize that the socket library must be included. How do you build the frozen exe file? Is there an option to explicitely include packages/modules? – User Aug 12 '17 at 16:27

0 Answers0