Python Forum
Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Debian 10 Buster Environment - Python 3.x (MariaDB 10.4.21) | Working Connector?
#1
Exclamation 
Hello again everyone! Admins, Mods (Thank you again for the prior threads, btw).

I am now up against parsing a huge amount of Data and the only way to do so is by learning Python.

I figure I would start with this thread; as I am at a stuck point with MySQL Connectors working with Debian 10 Buster and Python 3.x (No matter the solution; I cannot seem to get it working). Even the code from Oreilly Web Scraping with Python didn't work (I bought the Book).

Continuing;

I feel the best way to resolve this is to use a base line foundational block found from W3 Schools here https://www.w3schools.com/python/python_mysql_getstarted.asp

Code found in that block for Python Connector to MySQL is :
import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  password="yourpassword"
)

print(mydb) 
This is what happens when I run it:

python3 w3.mysql.python.connector.py 
Traceback (most recent call last):
  File "w3.mysql.python.connector.py", line 1, in <module>
    import mysql.connector
  File "/home/brandon/.local/lib/python3.5/site-packages/mysql/connector/__init__.py", line 54, in <module>
    from .connection import MySQLConnection
  File "/home/brandon/.local/lib/python3.5/site-packages/mysql/connector/connection.py", line 451
    f"This connection is using {tls_version} which is now "
                                                          ^
SyntaxError: invalid syntax
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)

“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)

#LetHISPeopleGo

Reply
#2
You should upgrade your Python version they have dropped support for Python 3.5 as you use now,need at least Python 3.6 preferably 3.9 -->.
f-sting(really good) that it fails now was one the update that was new in Python 3.6.
Works like this.
>>> tls_version = 2.2
>>> f"This connection is using {tls_version} which is now "
'This connection is using 2.2 which is now '
BrandonKastning likes this post
Reply
#3
Works for me with:

mysql-connector-python==8.0.27
And mariadb version 10.3.31

mysql  Ver 15.1 Distrib 10.3.31-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
Not sure this is relevant but all this in on Ubuntu 20.04.3 LTS.

It confuses me how TLS is getting into all this...
BrandonKastning likes this post
Reply
#4
(Nov-19-2021, 12:29 PM)ghoul Wrote: Not sure this is relevant but all this in on Ubuntu 20.04.3 LTS.
Ubuntu 20.04 comes with Python3 by default,then version is Python 3.8.5.
Then it will work,the problem is as mention that OP use Python 3.5(dropped support bye a lot of packages now).
Reply
#5
snippsat,

Thank you sir!

python3 --version
Python 3.5.3

I am looking into an upgrade as I type this! I will report the working commands that brings Python to a new 3.7/3.8/3.9 (Shooting for latest; 3.9.x).

It did not cross my mind that the python version was a factor in my problem(s) with Python and MariaDB. (This would deffinetly make Python more fun to learn; having data storage).



(Nov-19-2021, 11:43 AM)snippsat Wrote: You should upgrade your Python version they have dropped support for Python 3.5 as you use now,need at least Python 3.6 preferably 3.9 -->.
f-sting(really good) that it fails now was one the update that was new in Python 3.6.
Works like this.
>>> tls_version = 2.2
>>> f"This connection is using {tls_version} which is now "
'This connection is using 2.2 which is now '
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)

“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)

#LetHISPeopleGo

Reply
#6
ghoul,

Perhaps it's because I posted the incorrect version on the thread / OP.

I truly believed I was on Debian 10 Buster; however, after doing a

lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 9.13 (stretch)
Release: 9.13
Codename: stretch

I am using Debian 9.13 Stretch. Let's see what an upgrade does! Thank you both! I do know that I tested on Debian 10 also. Maybe that is why I thought I was still on it. I have formatted a couple times over the last 6 months fiddling with Python and MariaDB.



(Nov-19-2021, 12:29 PM)ghoul Wrote: Works for me with:

mysql-connector-python==8.0.27
And mariadb version 10.3.31

mysql  Ver 15.1 Distrib 10.3.31-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
Not sure this is relevant but all this in on Ubuntu 20.04.3 LTS.

It confuses me how TLS is getting into all this...
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)

“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)

#LetHISPeopleGo

Reply
#7
Is this the correct output for a working MySQL connector within Python 3.9.9?

brandon@FireDragon:~/Python/sgml.bs4$ python w3.mysql.python.connector.py 
<mysql.connector.connection.MySQLConnection object at 0x7fb325cfcac0>
brandon@FireDragon:~/Python/sgml.bs4$
Updated to 3.9.9 from source per the following Blogs/Tutorials:



Source Blogs/Tutorials (Google Found):

https://tecadmin.net/how-to-install-pyth...-debian-9/
https://stackoverflow.com/questions/6274...amed-mysql

apt update

apt upgrade

apt install wget build-essential libreadline-gplv2-dev libncursesw5-dev \
     libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev


wget https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz


tar xzf Python-3.9.9.tgz

cd Python-3.9.9

./configure --enable-optimizations
error output :

fi
WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
distutils: /usr/local/include/python3.9/UNKNOWN
sysconfig: /root/Python-3.9.9/Include/UNKNOWN
WARNING: Additional context:
user = False
home = None
root = '/'
prefix = None
Looking in links: /tmp/tmpi00_y1xa
Processing /tmp/tmpi00_y1xa/setuptools-58.1.0-py3-none-any.whl
Processing /tmp/tmpi00_y1xa/pip-21.2.4-py3-none-any.whl
Installing collected packages: setuptools, pip
  WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
  distutils: /usr/local/include/python3.9/setuptools
  sysconfig: /root/Python-3.9.9/Include/setuptools
  WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
  distutils: /usr/local/include/python3.9/pip
  sysconfig: /root/Python-3.9.9/Include/pip
Successfully installed pip-21.2.4 setuptools-58.1.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
root@FireDragon:~/Python-3.9.9#
root@FireDragon:~/Python-3.9.9# python3.9 -V
Python 3.9.9
root@FireDragon:~/Python-3.9.9#
pip3.9 -V
pip 21.2.4 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
nano -c /home/brandon/.bashrc

added the following 2 lines and saved:

alias python=python3.9
alias pip=pip3.9
brandon@FireDragon:~/Python/sgml.bs4$ python -V
Python 3.9.9
brandon@FireDragon:~/Python/sgml.bs4$ ./w3.mysql.python.connector.py
bash: ./w3.mysql.python.connector.py: Permission denied
brandon@FireDragon:~/Python/sgml.bs4$ python w3.mysql.python.connector.py 
Traceback (most recent call last):
  File "/home/brandon/Python/sgml.bs4/w3.mysql.python.connector.py", line 1, in <module>
    import mysql.connector
ModuleNotFoundError: No module named 'mysql'
brandon@FireDragon:~/Python/sgml.bs4$
brandon@FireDragon:~/Python/sgml.bs4$ pip install mariadb
Defaulting to user installation because normal site-packages is not writeable
Collecting mariadb
  Downloading mariadb-1.0.8.zip (85 kB)
     |████████████████████████████████| 85 kB 503 kB/s 
Using legacy 'setup.py install' for mariadb, since package 'wheel' is not installed.
Installing collected packages: mariadb
    Running setup.py install for mariadb ... done
Successfully installed mariadb-1.0.8
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python3.9 -m pip install --upgrade pip' command.
brandon@FireDragon:~/Python/sgml.bs4$ pip install mysql
brandon@FireDragon:~/Python/sgml.bs4$ pip install mysql
Defaulting to user installation because normal site-packages is not writeable
Collecting mysql
  Downloading mysql-0.0.3-py3-none-any.whl (1.2 kB)
Collecting mysqlclient
  Downloading mysqlclient-2.1.0.tar.gz (87 kB)
     |████████████████████████████████| 87 kB 708 kB/s 
Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient, mysql
    Running setup.py install for mysqlclient ... done
Successfully installed mysql-0.0.3 mysqlclient-2.1.0
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python3.9 -m pip install --upgrade pip' command.
brandon@FireDragon:~/Python/sgml.bs4$
brandon@FireDragon:~/Python/sgml.bs4$ python w3.mysql.python.connector.py 
Traceback (most recent call last):
  File "/home/brandon/Python/sgml.bs4/w3.mysql.python.connector.py", line 1, in <module>
    import mysql.connector
ModuleNotFoundError: No module named 'mysql'
brandon@FireDragon:~/Python/sgml.bs4$ pip install mysql-connector
Defaulting to user installation because normal site-packages is not writeable
Collecting mysql-connector
  Using cached mysql-connector-2.2.9.tar.gz (11.9 MB)
Using legacy 'setup.py install' for mysql-connector, since package 'wheel' is not installed.
Installing collected packages: mysql-connector
    Running setup.py install for mysql-connector ... done
Successfully installed mysql-connector-2.2.9
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python3.9 -m pip install --upgrade pip' command.
brandon@FireDragon:~/Python/sgml.bs4$
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)

“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)

#LetHISPeopleGo

Reply
#8
(Nov-20-2021, 03:57 AM)BrandonKastning Wrote: Is this the correct output for a working MySQL connector within Python 3.9.9?

brandon@FireDragon:~/Python/sgml.bs4$ python w3.mysql.python.connector.py 
<mysql.connector.connection.MySQLConnection object at 0x7fb325cfcac0>
brandon@FireDragon:~/Python/sgml.bs4$

Yeah, that is what I get, presumably the expected/correct output.
BrandonKastning likes this post
Reply
#9
ghoul,

Excellent Tim! Thank you!

Alright! Time to roll up my sleeves for another go at Python Parsing to MariaDB! I will make threads to track my progress and share with the world my pain and successes provided I have any.

Best Regards,

Brandon


(Nov-20-2021, 04:55 AM)ghoul Wrote:
(Nov-20-2021, 03:57 AM)BrandonKastning Wrote: Is this the correct output for a working MySQL connector within Python 3.9.9?

brandon@FireDragon:~/Python/sgml.bs4$ python w3.mysql.python.connector.py 
<mysql.connector.connection.MySQLConnection object at 0x7fb325cfcac0>
brandon@FireDragon:~/Python/sgml.bs4$

Yeah, that is what I get, presumably the expected/correct output.
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)

“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)

#LetHISPeopleGo

Reply
#10
I am currently on my Debian 10 Buster machine. Currently has Python 3.7.x on it. I followed these directions that I used to get my Debian 9 Stretch up to 3.9.9 and realized I forgot a step.

After line 16 on installation (above):

After ./configure

make altinstall
then

nano ~/.bashrc
add the following lines: (source by Abhishek in comments of top URL in source links) which allows it to be the default for "python3" -- python 3.9.9

alias python=python3.9
alias pip=pip3.9
Save and Exit! (Should be in root) Big Grin
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)

“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)

#LetHISPeopleGo

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Python Obstacles | Jeet-Kune-Do | BS4 (Tags > MariaDB) [URL/Local HTML] BrandonKastning 0 1,400 Feb-08-2022, 08:55 PM
Last Post: BrandonKastning
Question Securing State Constitutions (USA) from University of Maryland > MariaDB .sql BrandonKastning 1 1,495 Jan-21-2022, 06:34 PM
Last Post: BrandonKastning
Lightbulb Python Obstacles | Kung-Fu | Full File HTML Document Scrape and Store it in MariaDB BrandonKastning 5 2,817 Dec-29-2021, 02:26 AM
Last Post: BrandonKastning
  Python Obstacles | American Kenpo | Wiki Scrape URL/Table and Store it in MariaDB BrandonKastning 6 2,783 Dec-29-2021, 12:38 AM
Last Post: BrandonKastning
  Python Obstacles | Karate | HTML/Scrape Specific Tag and Store it in MariaDB BrandonKastning 8 3,090 Nov-22-2021, 01:38 AM
Last Post: BrandonKastning
  mod-python in apache2 on debian 9 xstation 6 3,759 Jun-15-2020, 01:29 PM
Last Post: DeaD_EyE
  Build a simple Webapp with Python Flask and mariaDB newbie1 3 3,317 Jun-04-2020, 09:34 PM
Last Post: lmolter54
  Python3 + BeautifulSoup4 + lxml (HTML -> CSV) - How to write 3 Columns to MariaDB? BrandonKastning 21 6,712 Mar-23-2020, 05:51 PM
Last Post: ndc85430
  [Flask] Create new project for add user,edit,delete,view users in python with mysql connector chandranmanikandan 0 7,294 Oct-30-2018, 10:19 AM
Last Post: chandranmanikandan
  Eclipse Python We development Environment Adelton 3 4,528 Feb-16-2017, 08:52 PM
Last Post: Adelton

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020