python mariadb & html tables

Larry Martell larry.martell at gmail.com
Tue Sep 15 14:51:30 EDT 2020


On Tue, Sep 15, 2020 at 11:45 AM SS <sami.strat at gmail.com> wrote:
>
> I'm trying to create an table in html from a Maria DB table, from a python script.  I'm getting some unexpected results.
>
> The environment is Centos 7, I'm using Python3 with apache.
>
> Here is copy of the script I'm using:
>
> ******* SCRIPT START *********
>
> import mysql.connector
> import cgitb
> cgitb.enable()
>
> mydb = mysql.connector.connect(
>   host="localhost",
>   user="root",
>   password="somepassword",
>   database="somedb"
> )
>
> mycursor = mydb.cursor()
>
> mycursor.execute("select name, provisioned_space, used_space, memory_size, cpus, ip_address, host_cpu, host_mem from projecttable where name like '%newproject%'")
>
> myresult = mycursor.fetchall()
>
> print "Content-type: text/plain:charset=utf-8"
> print
> for x in myresult:
>   print(x)
>
>
> ******* SCRIPT STOPS *********
>
> It works.  But I get alot of extraneous data I don't need or want.  Here is an example of the output:
>
> ********* OUTPUT STARTS ***********
>
> Content-type: text/plain:charset=utf-8
>
> (u'host1.mydomain.com', u'106.11 GB', u'32.72 GB', u'1 GB', u'1', u'172.18.33.62', u'Running', u'16 MHz')
> (u'hopst2.mydomain.com', u'106.08 GB', u'56.87 GB', u'1 GB', u'1', u'172.17.4.82', u'Running', u'0 Hz')
>
> ********* OUTPUT STOPS ***********
>
> Is this typical of Python?  Do I need create another script to clean up the output?  Or is there a better way to extract data from a MariaDB instance, and put it in an HTML table? Any advise would be appreciated.

What is the extraneous data?


More information about the Python-list mailing list