Python can't connect to XAMPP

Problems with the Mac OS X version of XAMPP, questions, comments, and anything related.

Python can't connect to XAMPP

Postby robertoneto123 » 03. October 2020 22:55

Hello,

I have a Python Script that connects to a MySQL database. I used the same following procedure, but when I run on a MacOS, the script freezes when I attempt to connect.

1. Install Python 64 bits
2. Install mysql module
3. Install latest version of XAMPP
4. Open "localhost", phpMyAdmin works fine

To connect, I'm using:
db_connection = mysql.connector.connect(host='localhost', user='root', password='', database='mydb')

The script freezes then. The following line (a "print") is not executed. I left for about 5 minutes and I did not get even a timeout...

Any clues? Is MAC blocking something?

Thanks!
robertoneto123
 
Posts: 4
Joined: 03. October 2020 22:47
XAMPP version: 7.4.10
Operating System: MacOS

Re: Python can't connect to XAMPP

Postby Nobbie » 04. October 2020 11:43

Due to Python Documentation, you are passing the arguments in the wrong order. The host (localhost) should not be the first argument, but the third instead:

Code: Select all
db_connection = mysql.connector.connect(user='root', password='', host='localhost', database='mydb')


I dont know if this is important in Python (i am not a Python programmer, but for PHP, C, Pascal etc. the order of the parameter is important), its the only thing that came to my mind.
Nobbie
 
Posts: 13214
Joined: 09. March 2008 13:04

Re: Python can't connect to XAMPP

Postby robertoneto123 » 04. October 2020 19:55

Unfortunately, in Python the order of arguments (when labeled) is not important. And this code works on Windows and Linux.

It's something with MacOS... but I cannot figure it out what.
robertoneto123
 
Posts: 4
Joined: 03. October 2020 22:47
XAMPP version: 7.4.10
Operating System: MacOS

Re: Python can't connect to XAMPP

Postby Nobbie » 05. October 2020 10:40

A firewall? A security tool? I dont have any MacOS PC.
Nobbie
 
Posts: 13214
Joined: 09. March 2008 13:04

Re: Python can't connect to XAMPP

Postby robertoneto123 » 05. October 2020 12:11

Nobbie wrote:A firewall? A security tool? I dont have any MacOS PC.


I searched for a firewall, with no success. But since phpMyAdmin works, I believe that the port is not blocked.

What puzzles me is that I don't get even a timeout error. The script just freezes when try to establish the connection.

Thanks!
robertoneto123
 
Posts: 4
Joined: 03. October 2020 22:47
XAMPP version: 7.4.10
Operating System: MacOS

Re: Python can't connect to XAMPP

Postby Nobbie » 05. October 2020 18:05

robertoneto123 wrote:What puzzles me is that I don't get even a timeout error. The script just freezes when try to establish the connection.


You are absolutely right, freezing is bad, very bad. Freezing is not a controled behaviour, mostly its a severe addressing error or similar. Is there a problem with 64bit vs. 32bit (only a clue)? If i were you, i would go for a cheap Linux PC and run Xampp there. That does not cost much money, its stable, its Linux (i love Linux). A used PC from Ebay for lets say 50 bugs will do the job. You can keep your MacOS PC as a develoment environment, for testing purpose move your scripts and files to the Linux server and you are done.
Nobbie
 
Posts: 13214
Joined: 09. March 2008 13:04

Re: Python can't connect to XAMPP

Postby robertoneto123 » 05. October 2020 18:52

Nobbie wrote:You are absolutely right, freezing is bad, very bad. Freezing is not a controled behaviour, mostly its a severe addressing error or similar. Is there a problem with 64bit vs. 32bit (only a clue)? If i were you, i would go for a cheap Linux PC and run Xampp there. That does not cost much money, its stable, its Linux (i love Linux). A used PC from Ebay for lets say 50 bugs will do the job. You can keep your MacOS PC as a develoment environment, for testing purpose move your scripts and files to the Linux server and you are done.


My workaround was something like that. I run a Docker image with mysql. For some reason beyond my comprehension, the python code works on the docker container with mysql. But does not on XAMPP. Again, the same code works fine on Windows and Linux. I've tested the same code on two MacOS with same issue.

For future reference, to use Docker as I did, just create a file docker-compose.yml with the code:
Code: Select all
version: '3.3'
volumes:
  data:
services:
  db:
    image: mysql:5.6
    ports:
      - "3306:3306"
    volumes:
      - data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_DATABASE=automacao
  app:
    image: phpmyadmin/phpmyadmin:latest
    links:
      - db
    ports:
      - 80:80
    environment:
      - PMA_ARBITRARY=1


And run it by

Code: Select all
sudo docker-compose up app
robertoneto123
 
Posts: 4
Joined: 03. October 2020 22:47
XAMPP version: 7.4.10
Operating System: MacOS


Return to XAMPP for macOS

Who is online

Users browsing this forum: No registered users and 69 guests