IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bibliothèques tierces Python Discussion :

Connexion impossible à Mysql depuis mon code Python (Access denied) [Python 3.X]


Sujet :

Bibliothèques tierces Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Mars 2018
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Chargé d'affaire

    Informations forums :
    Inscription : Mars 2018
    Messages : 4
    Par défaut Connexion impossible à Mysql depuis mon code Python (Access denied)
    Bonjour,

    Je sollicite votre aide pour mon problème car j'ai tout essayé sans succès. Je suis débutant en langage Python et je cherche à alimenter mon programme avec une base de donnée Mysql, le problème est que je n'arrive pas à m'y connecter avec le code ci dessous :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    conn = mysql.connector.connect(user='Alexis', password='********',
                                  host='localhost',
                                  database='srp')
    cursor = conn.cursor()
    conn.close()
    la réponse de la console est la suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    C:\Users\Alexis LAILLE\Python>python Mysql.py
    Traceback (most recent call last):
      File "Mysql.py", line 16, in <module>
        database='srp')
      File "C:\Users\Alexis LAILLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\__init__.py", line 184, in connect
        return MySQLConnection(*args, **kwargs)
      File "C:\Users\Alexis LAILLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\connection.py", line 100, in __init__
        self.connect(**kwargs)
      File "C:\Users\Alexis LAILLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\abstracts.py", line 733, in connect
        self._open_connection()
      File "C:\Users\Alexis LAILLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\connection.py", line 244, in _open_connection
        self._ssl)
      File "C:\Users\Alexis LAILLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\connection.py", line 165, in _do_auth
        self._auth_switch_request(username, password)
      File "C:\Users\Alexis LAILLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\connection.py", line 209, in _auth_switch_request
        raise errors.get_exception(packet)
    mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'Alexis'@'localhost' (using password: YES)
    Je précise qu'il ne s'agit pas d'un problème de mot de passe car je n'ai aucun mal à m'y connecter depuis Mysql Workbench ou encore avec la console mysql.
    J'ai essayé de me connecter en user='root', changer le host='localhost' en host='127.0.0.1' ou host='%', d'ailleurs cette dernière solution donne le résultat suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
    Traceback (most recent call last):
      File "Mysql.py", line 16, in <module>
        database='srp')
      File "C:\Users\Alexis LAILLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\__init__.py", line 184, in connect
        return MySQLConnection(*args, **kwargs)
      File "C:\Users\Alexis LAILLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\connection.py", line 100, in __init__
        self.connect(**kwargs)
      File "C:\Users\Alexis LAILLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\abstracts.py", line 733, in connect
        self._open_connection()
      File "C:\Users\Alexis LAILLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\connection.py", line 240, in _open_connection
        self._socket.open_connection()
      File "C:\Users\Alexis LAILLE\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mysql\connector\network.py", line 506, in open_connection
        errno=2003, values=(self.get_address(), _strioerror(err)))
    mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '%:3306' (11001 getaddrinfo failed)

    j'ai testé les commandes "GRANT ALL PRIVILEGE..." sans succès

    Merci par avance à tous ceux qui pourront apporter leur aide concernant mon problème.

    Alexis,

  2. #2
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 746
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 746
    Par défaut
    Salut,

    Citation Envoyé par Alex44L Voir le message
    Je précise qu'il ne s'agit pas d'un problème de mot de passe car je n'ai aucun mal à m'y connecter depuis Mysql Workbench ou encore avec la console mysql
    Avec la console mysql, essayez de vous connecter via le protocole TCP - ce qu'essaie de faire Python -. Ce n'est que si ça fonctionne que çà deviendra un soucis Python (et encore).

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Mars 2018
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Chargé d'affaire

    Informations forums :
    Inscription : Mars 2018
    Messages : 4
    Par défaut
    Bonjour,
    Merci pour la réponse, alors voici ci dessous ce que j'ai testé

    Commande : mysql -u root -p --host=127.0.0.1 --protocol=TCP
    réponse
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    Enter password: **********
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
    On me demande le mot de passe, puis "acces denied"
    Même résultat avec -u Alexis.


    La seule commande qui fonctionne est la suivante : mysql -u root -p --host=localhost --protocol=TCP (fonctionne aussi avec -u Alexis)

  4. #4
    Futur Membre du Club
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Mars 2018
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Chargé d'affaire

    Informations forums :
    Inscription : Mars 2018
    Messages : 4
    Par défaut
    J'ai quelques autres éléments à apporter, peut-être que celà n'a pas de lien, mais je préfère tout indiquer !

    1- Problème Mysql Installer
    J'ai essayé d'installer depuis MySQL Installer, l'élément Connector/Python 2.1 for Python 3.4, mais impossible car message d'erreur "Python 3.4 is not installed"

    2- Problème avec les modules Python

    J'ai des difficultés à installer les modules mysql (suivant un tutoriel)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
     
    C:\Users\Alexis LAILLE\Python>pip install mysql
    Collecting mysql
      Using cached mysql-0.0.1.tar.gz
    Collecting MySQL-python (from mysql)
      Using cached MySQL-python-1.2.5.zip
    Installing collected packages: MySQL-python, mysql
      Running setup.py install for MySQL-python ... error
        Complete output from command "c:\users\alexis laille\appdata\local\programs\python\python36-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\ALEXIS~1\\AppData\\Local\\Temp\\pip-build-ova08sgd\\MySQL-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\ALEXIS~1\AppData\Local\Temp\pip-mx5gkfhm-record\install-record.txt --single-version-externally-managed --compile:
        running install
        running build
        running build_py
        creating build
        creating build\lib.win32-3.6
        copying _mysql_exceptions.py -> build\lib.win32-3.6
        creating build\lib.win32-3.6\MySQLdb
        copying MySQLdb\__init__.py -> build\lib.win32-3.6\MySQLdb
        copying MySQLdb\converters.py -> build\lib.win32-3.6\MySQLdb
        copying MySQLdb\connections.py -> build\lib.win32-3.6\MySQLdb
        copying MySQLdb\cursors.py -> build\lib.win32-3.6\MySQLdb
        copying MySQLdb\release.py -> build\lib.win32-3.6\MySQLdb
        copying MySQLdb\times.py -> build\lib.win32-3.6\MySQLdb
        creating build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\__init__.py -> build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\CR.py -> build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\ER.py -> build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\REFRESH.py -> build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.6\MySQLdb\constants
        running build_ext
        building '_mysql' extension
        error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
     
        ----------------------------------------
    Command ""c:\users\alexis laille\appdata\local\programs\python\python36-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\ALEXIS~1\\AppData\\Local\\Temp\\pip-build-ova08sgd\\MySQL-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\ALEXIS~1\AppData\Local\Temp\pip-mx5gkfhm-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\ALEXIS~1\AppData\Local\Temp\pip-build-ova08sgd\MySQL-python\
     
    C:\Users\Alexis LAILLE\Python>pip install mysqlclient
    Collecting mysqlclient
      Downloading mysqlclient-1.3.12-cp36-cp36m-win32.whl (1.2MB)
        100% |████████████████████████████████| 1.2MB 364kB/s
    Installing collected packages: mysqlclient
    Successfully installed mysqlclient-1.3.12
     
    C:\Users\Alexis LAILLE\Python>pip install MySQL-python
    Collecting MySQL-python
      Using cached MySQL-python-1.2.5.zip
    Installing collected packages: MySQL-python
      Running setup.py install for MySQL-python ... error
        Complete output from command "c:\users\alexis laille\appdata\local\programs\python\python36-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\ALEXIS~1\\AppData\\Local\\Temp\\pip-build-jhx58ub9\\MySQL-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\ALEXIS~1\AppData\Local\Temp\pip-t2cuqhx1-record\install-record.txt --single-version-externally-managed --compile:
        running install
        running build
        running build_py
        creating build
        creating build\lib.win32-3.6
        copying _mysql_exceptions.py -> build\lib.win32-3.6
        creating build\lib.win32-3.6\MySQLdb
        copying MySQLdb\__init__.py -> build\lib.win32-3.6\MySQLdb
        copying MySQLdb\converters.py -> build\lib.win32-3.6\MySQLdb
        copying MySQLdb\connections.py -> build\lib.win32-3.6\MySQLdb
        copying MySQLdb\cursors.py -> build\lib.win32-3.6\MySQLdb
        copying MySQLdb\release.py -> build\lib.win32-3.6\MySQLdb
        copying MySQLdb\times.py -> build\lib.win32-3.6\MySQLdb
        creating build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\__init__.py -> build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\CR.py -> build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\ER.py -> build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\REFRESH.py -> build\lib.win32-3.6\MySQLdb\constants
        copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.6\MySQLdb\constants
        running build_ext
        building '_mysql' extension
        error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
     
        ----------------------------------------
    Command ""c:\users\alexis laille\appdata\local\programs\python\python36-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\ALEXIS~1\\AppData\\Local\\Temp\\pip-build-jhx58ub9\\MySQL-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\ALEXIS~1\AppData\Local\Temp\pip-t2cuqhx1-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\ALEXIS~1\AppData\Local\Temp\pip-build-jhx58ub9\MySQL-python\
     
    C:\Users\Alexis LAILLE\Python>pip install mysql-connector-python --allow-external mysql-connector-python
    DEPRECATION: --allow-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.
    Requirement already satisfied: mysql-connector-python in c:\users\alexis laille\appdata\local\programs\python\python36-32\lib\site-packages
    j'ai installé visual C++ 2015, visual C++2017, Visual Studio 2017 (je ne trouve plus visual Studio2015), sans succès.

    Pourtant le module mysql.connector doit être déjà présent car je n'ai pas de message d'erreur à ce sujet avec le "import"

    Bref, dur dur la frustration du débutant !

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Chargé d'affaire
    Inscrit en
    Mars 2018
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Chargé d'affaire

    Informations forums :
    Inscription : Mars 2018
    Messages : 4
    Par défaut
    Après 2 jours de galère, j'ai réussi !

    j'ai installé MySQLdb à la place de mysql.connector. tout fonctionne !


    Si j'ai bien compris mysql.connector, c'est trop ancien ?


    Merci pour votre forum, j'ai pu trouver ces info grâce à vous

    Alexis

  6. #6
    Expert confirmé

    Homme Profil pro
    Directeur des systèmes d'information
    Inscrit en
    Avril 2002
    Messages
    2 891
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 65
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Directeur des systèmes d'information
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2002
    Messages : 2 891
    Par défaut
    Pour te faciliter la tache tu devrais suivre un autre tutoriel Python, le mieux c'est ce livre gratuit, très bien fait et très complet : Apprendre à programmer avec Python 3 par Gérard Swinnen

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Connexion a MySQL depuis PHP
    Par lamelfa dans le forum SQL Procédural
    Réponses: 7
    Dernier message: 13/09/2006, 19h37
  2. Réponses: 3
    Dernier message: 31/07/2006, 15h07
  3. connexion base mysql depuis internet
    Par brancaleone dans le forum Delphi .NET
    Réponses: 3
    Dernier message: 07/04/2006, 16h08
  4. [VB]Connexion du DataEnvironment depuis le code
    Par Bouassa dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 27/01/2006, 19h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo