[help]python script connect to mysql
#1
i have some problem with xbmc, when i use python connect to mysql with pyhton script it can update, select, delete database on mysql. but when i combine python script to xbmc xml it can't connect to database this is my log from xbmc.log :


08:54:50 T:2972699504 M:372703232 NOTICE: -->Python Interpreter Initialized<--
08:54:50 T:2972699504 M:372703232 ERROR: Error Type: exceptions.ImportError
08:54:50 T:2972699504 M:372695040 ERROR: Error Contents: No module named MySQLdb
08:54:50 T:2972699504 M:372695040 ERROR: Traceback (most recent call last):
File "/home/xbmc/.xbmc/script/sql.py", line 4, in ?
import MySQLdb as mdb
ImportError: No module named MySQLdb



and this is my sql.py :

import MySQLdb

conn = mySQLdb.Connect(host='localhost',user='ivan',\
password='ivan123',database='ivan')

c = conn.cursor()

c.execute("""drop table if exists towns""")
c.execute("""drop table if exists hotels""")

conn.commit()

c.execute("""create table towns (
tid int primary key not NULL ,
name text,
postcode text)""")

c.execute("""create table hotels (
hid int primary key not NULL ,
tid int,
name text,
address text,
rooms int,
rate float)""")

c.execute("""insert into towns values (1, "Melksham", "SN12")""")
c.execute("""insert into towns values (2, "Cambridge", "CB1")""")
c.execute("""insert into towns values (3, "Foxkilo", "CB22")""")

c.execute("""insert into hotels values (1, 2, "Hamilkilo Hotel", "Chesterton Road", 15, 40.)""")
c.execute("""insert into hotels values (2, 2, "Arun Dell", "Chesterton Road", 60, 70.)""")
c.execute("""insert into hotels values (3, 2, "Crown Plaza", "Downing Street", 100, 105.)""")
c.execute("""insert into hotels values (4, 1, "Well House Manor", "Spa Road", 5, 80.)""")
c.execute("""insert into hotels values (5, 1, "Beechfield House", "The Main Road", 26, 110.)""")

conn.commit()

c.execute ("""select * from towns left join hotels on towns.tid = hotels.tid""")

for row in c:
print (row)

c.close()

from the log import MySQLdb as mdb
ImportError: No module named MySQLdb


can anyone advise me how can i solve this problem
Reply
#2
I assume you're using Dharma.

If so, you'll need to copy the MySQLdb modules into your script folder.
I think you need to copy:
  • MySQLdb (folder)
  • _mysql.so
  • _mysql_exceptions.py
  • _mysql_exceptions.pyc
  • _mysql_exceptions.pyo

Also, it doesn't look like this script is located in your addons directory. Is that on purpose?
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#3
el_Paraguayo Wrote:I assume you're using Dharma.

If so, you'll need to copy the MySQLdb modules into your script folder.
I think you need to copy:
  • MySQLdb (folder)
  • _mysql.so
  • _mysql_exceptions.py
  • _mysql_exceptions.pyc
  • _mysql_exceptions.pyo

Also, it doesn't look like this script is located in your addons directory. Is that on purpose?

yes i am using dharma version, i will try for your suggestion and report back, i hope this will solve this problems Big Grin, but for my question where i must put the :
  • MySQLdb (folder)
  • _mysql.so
  • _mysql_exceptions.py
  • _mysql_exceptions.pyc
  • _mysql_exceptions.pyo

or i must create my own addon for those ? because i use my script like this " XBMC.RunScript(/home/xbmc/.xbmc/script/sql.py) "
Reply
#4
el_Paraguayo Wrote:I assume you're using Dharma.

If so, you'll need to copy the MySQLdb modules into your script folder.
I think you need to copy:
  • MySQLdb (folder)
  • _mysql.so
  • _mysql_exceptions.py
  • _mysql_exceptions.pyc
  • _mysql_exceptions.pyo

Also, it doesn't look like this script is located in your addons directory. Is that on purpose?

awesome thanks very much it really work with me Big Grin
Reply
#5
I have the same problem

where did you put

MySQLdb (folder)
_mysql.so
_mysql_exceptions.py
_mysql_exceptions.pyc
_mysql_exceptions.pyo


system/xbmc/python/lib?
Reply

Logout Mark Read Team Forum Stats Members Help
[help]python script connect to mysql0