Re: mysqldb error

2006-04-12 Thread Graham Dumpleton


On 13/04/2006, at 5:26 AM, Firat KUCUK wrote:


Hi,
i wrote a simple connection script.
It works as a command line script or cgi script.
But does not work in mod_python.

import MySQLdb
conn = MySQLdb.connect(
  host   = '127.0.0.1',
  user   = 'pismikrop',
  passwd = 'pass',
  db = 'db')
print conn
conn.close()

command-line and cgi output:
<_mysql.connection open to '127.0.0.1' at 81a304c>

mod_python output:
<_mysql.connection open to '(null)' at 82ac504>

i cannot execute MySQL queries. What should i do?


Can you supply the remainder of your mod_python handler code
so we can see the context in which this used? Minimal but complete
as possible is preferable.

If the above is truly exactly how you are using it, you probably aren't
using mod_python but a CGI scripts as "print" statement will not
output anywhere in mod_python so you wouldn't be able to capture
it.

Graham


Re: mysqldb error

2006-04-12 Thread Deron Meranda
On 4/12/06, Firat KUCUK <[EMAIL PROTECTED]> wrote:
> conn = MySQLdb.connect(
>host   = '127.0.0.1',
>user   = 'pismikrop',
>passwd = 'pass',
>db = 'db')

Unrelated to your question, but I see this a lot.  You should
not hardcode the database password in your script.  If your
script ever fails you may end up with a Python traceback, and
if PythonDebug is enabled (or you're using a framework on
top of mod_python) parts of your source code could be
dumped across the HTML output, including your password!

In web scripts, you should always read any passwords, etc.,
from some other place such as a file.

pw = open('.htdbpass','r').readline().strip()
conn = MySQLdb.connect(
host   = '127.0.0.1',
user   = 'pismikrop',
passwd = pw,
db = 'db')
--
Deron Meranda


Re: mysqldb error

2006-04-12 Thread Barry Pearce




One extra comment on this...

Firstly make sure you have upgraded to the latest version of MySQLdb - we found earlier versions less than great.

Warning: If you have PHP installed it uses mysql client libraries which are OUT OF DATE - and will cause failures. Remove the php module from the server and try again.


We use MySQL 4.1 servers quite happily from mod_python under both win32 and linux.



Deron Meranda wrote:

  On 4/12/06, Firat KUCUK <[EMAIL PROTECTED]> wrote:
  
  
conn = MySQLdb.connect(
   host   = '127.0.0.1',
   user   = 'pismikrop',
   passwd = 'pass',
   db = 'db')

  
  
Unrelated to your question, but I see this a lot.  You should
not hardcode the database password in your script.  If your
script ever fails you may end up with a Python traceback, and
if PythonDebug is enabled (or you're using a framework on
top of mod_python) parts of your source code could be
dumped across the HTML output, including your password!

In web scripts, you should always read any passwords, etc.,
from some other place such as a file.

pw = open('.htdbpass','r').readline().strip()
conn = MySQLdb.connect(
host   = '127.0.0.1',
user   = 'pismikrop',
passwd = pw,
db = 'db')
--
Deron Meranda

  





Re: mysqldb error

2006-04-12 Thread Firat KUCUK




Barry Pearce yazmış:

  
  One extra comment on this...

Firstly make sure you have upgraded to the latest version of MySQLdb - we found earlier versions less than great.

Warning: If you have PHP installed it uses mysql client libraries which are OUT OF DATE - and will cause failures. Remove the php module from the server and try again.


We use MySQL 4.1 servers quite happily from mod_python under both win32 and linux.
  
  
  
Deron Meranda wrote:
  
On 4/12/06, Firat KUCUK <[EMAIL PROTECTED]> wrote:
  

  conn = MySQLdb.connect(
   host   = '127.0.0.1',
   user   = 'pismikrop',
   passwd = 'pass',
   db = 'db')



Unrelated to your question, but I see this a lot.  You should
not hardcode the database password in your script.  If your
script ever fails you may end up with a Python traceback, and
if PythonDebug is enabled (or you're using a framework on
top of mod_python) parts of your source code could be
dumped across the HTML output, including your password!

In web scripts, you should always read any passwords, etc.,
from some other place such as a file.

pw = open('.htdbpass','r').readline().strip()
conn = MySQLdb.connect(
host   = '127.0.0.1',
user   = 'pismikrop',
passwd = pw,
db = 'db')
--
Deron Meranda

  
  

my distro is ubuntu breezy,
I used cgi handler. And text mime type
so i can view the print statement.

MySQL server 4.0.24
apache 2.0.54
python2.4-mysqldb 1.2.1

php, console python, cgi python works fine.

my .htaccess file

Allow from   All

AddHandler   mod_python .py
PythonHandlermod_python.cgihandler
PythonDebug  On

DirectoryIndex   index.htm index.html index.php index.py index.pl

-

#! /usr/bin/python
# -*- coding: UTF-8 -*-

print 'Content-Type: text/plain\n'

import MySQLdb
conn = MySQLdb.connect(
   host   = '127.0.0.1',
   user   = 'pismikrop',
   passwd = 'pass',
   db = 'gate')
print conn
conn.close()


---

output: 
<_mysql.connection open to '(null)' at 82a97e4>


if host = '10.0.0.6'

Mod_python error: "PythonHandler mod_python.cgihandler"

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
result = object(req)

  File "/usr/lib/python2.4/site-packages/mod_python/cgihandler.py", line 96, in handler
imp.load_module(module_name, fd, path, desc)

  File "/home/pismikrop/vhosts/mikropyuvasi/content/tests/mpcgi/firat.py", line 11, in ?
db = 'gate')

  File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line 66, in Connect
return Connection(*args, **kwargs)

  File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 134, in __init__
super(Connection, self).__init__(*args, **kwargs2)

OperationalError: (2003, "Can't connect to MySQL server on '10.0.0.6' (111)")

--

mysql> SELECT User, Host FROM user;
+--+--+
| User | Host |
+--+--+
| pismikrop| %|
| debian-sys-maint | localhost|
| root | localhost|
| root | mikropyuvasi |
+--+--+

pismikrop user has all priviliges to all databases.






Re: mysqldb error

2006-04-12 Thread Graham Dumpleton
Apache doesn't probably run as any of the users which your database
allows access to. Add lines in your CGI which says:

  import os
  print os.getuid()

and then see what user that UID actually is and give it access. User
may be something like "apache", "www", "wwwroot" or possibly even
"nobody" depending on the system configuration.

You can also check your Apache configuration for lines:

User www
Group www

to see what it runs as:

Graham

Firat KUCUK wrote ..
> my distro is ubuntu breezy,
> I used cgi handler. And text mime type
> so i can view the print statement.
> 
> MySQL server 4.0.24
> apache 2.0.54
> python2.4-mysqldb 1.2.1
> 
> php, console python, cgi python works fine.
> 
> my .htaccess file
> 
> Allow from   All
> 
> AddHandler   mod_python .py
> PythonHandlermod_python.cgihandler
> PythonDebug  On
> 
> DirectoryIndex   index.htm index.html index.php index.py index.pl
> 
> -
> 
> #! /usr/bin/python
> # -*- coding: UTF-8 -*-
> 
> print 'Content-Type: text/plain\n'
> 
> import MySQLdb
> conn = MySQLdb.connect(
>host   = '127.0.0.1',
>user   = 'pismikrop',
>passwd = 'pass',
>db = 'gate')
> print conn
> conn.close()
> 
> 
> ---
> 
> output: 
> <_mysql.connection open to '(null)' at 82a97e4>
> 
> 
> if host = '10.0.0.6'
> 
> Mod_python error: "PythonHandler mod_python.cgihandler"
> 
> Traceback (most recent call last):
> 
>   File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299,
> in HandlerDispatch
> result = object(req)
> 
>   File "/usr/lib/python2.4/site-packages/mod_python/cgihandler.py", line
> 96, in handler
> imp.load_module(module_name, fd, path, desc)
> 
>   File "/home/pismikrop/vhosts/mikropyuvasi/content/tests/mpcgi/firat.py",
> line 11, in ?
> db = 'gate')
> 
>   File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line 66,
> in Connect
> return Connection(*args, **kwargs)
> 
>   File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line
> 134, in __init__
> super(Connection, self).__init__(*args, **kwargs2)
> 
> OperationalError: (2003, "Can't connect to MySQL server on '10.0.0.6' (111)")
> 
> --
> 
> mysql> SELECT User, Host FROM user;
> +--+--+
> | User | Host |
> +--+--+
> | pismikrop| %|
> | debian-sys-maint | localhost|
> | root | localhost|
> | root | mikropyuvasi |
> +--+--+
> 
> pismikrop user has all priviliges to all databases.


Re: mysqldb error

2006-04-12 Thread Graham Dumpleton
Whoops. I could be talking nonsense here. But  then I missed that
your code says 127.0.0.1 yet the error says 10.0.0.6.

FWIW, the reason that I thought to suggest to look at this was that
I was using a database once where using 127.0.0.1 made it use
a local database connection rather than full IP connection and in
that situation, for whatever reason it actually ignored the user name
in the login and was using the user ID of the process connecting
to the database to determine privileges.

I rarely use databases, so could though be completely wrong and
misunderstood what I saw at the time. :-(

Someone who knows what they are talking about should step in
and save me now. :-)

Graham

Graham Dumpleton wrote ..
> Apache doesn't probably run as any of the users which your database
> allows access to. Add lines in your CGI which says:
> 
>   import os
>   print os.getuid()
> 
> and then see what user that UID actually is and give it access. User
> may be something like "apache", "www", "wwwroot" or possibly even
> "nobody" depending on the system configuration.
> 
> You can also check your Apache configuration for lines:
> 
> User www
> Group www
> 
> to see what it runs as:
> 
> Graham
> 
> Firat KUCUK wrote ..
> > my distro is ubuntu breezy,
> > I used cgi handler. And text mime type
> > so i can view the print statement.
> > 
> > MySQL server 4.0.24
> > apache 2.0.54
> > python2.4-mysqldb 1.2.1
> > 
> > php, console python, cgi python works fine.
> > 
> > my .htaccess file
> > 
> > Allow from   All
> > 
> > AddHandler   mod_python .py
> > PythonHandlermod_python.cgihandler
> > PythonDebug  On
> > 
> > DirectoryIndex   index.htm index.html index.php index.py index.pl
> > 
> > -
> > 
> > #! /usr/bin/python
> > # -*- coding: UTF-8 -*-
> > 
> > print 'Content-Type: text/plain\n'
> > 
> > import MySQLdb
> > conn = MySQLdb.connect(
> >host   = '127.0.0.1',
> >user   = 'pismikrop',
> >passwd = 'pass',
> >db = 'gate')
> > print conn
> > conn.close()
> > 
> > 
> > ---
> > 
> > output: 
> > <_mysql.connection open to '(null)' at 82a97e4>
> > 
> > 
> > if host = '10.0.0.6'
> > 
> > Mod_python error: "PythonHandler mod_python.cgihandler"
> > 
> > Traceback (most recent call last):
> > 
> >   File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line
> 299,
> > in HandlerDispatch
> > result = object(req)
> > 
> >   File "/usr/lib/python2.4/site-packages/mod_python/cgihandler.py", line
> > 96, in handler
> > imp.load_module(module_name, fd, path, desc)
> > 
> >   File "/home/pismikrop/vhosts/mikropyuvasi/content/tests/mpcgi/firat.py",
> > line 11, in ?
> > db = 'gate')
> > 
> >   File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line 66,
> > in Connect
> > return Connection(*args, **kwargs)
> > 
> >   File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line
> > 134, in __init__
> > super(Connection, self).__init__(*args, **kwargs2)
> > 
> > OperationalError: (2003, "Can't connect to MySQL server on '10.0.0.6'
> (111)")
> > 
> > --
> > 
> > mysql> SELECT User, Host FROM user;
> > +--+--+
> > | User | Host |
> > +--+--+
> > | pismikrop| %|
> > | debian-sys-maint | localhost|
> > | root | localhost|
> > | root | mikropyuvasi |
> > +--+--+
> > 
> > pismikrop user has all priviliges to all databases.


Re: mysqldb error

2006-04-12 Thread Deron Meranda
> OperationalError: (2003, "Can't connect to MySQL server on '10.0.0.6' (111)")

Error 111 is a socket connection refused (ECONNREFUSED).  So most
likely this has nothing to do with your db username or password.  But
the ip address does look unusual.

First, does the ip 10.0.0.6 mean anything?  Is it an address of one of
your interfaces?  Use "/sbin/ip addr list" to find out.

Do you have SELinux enabled?  Run /usr/sbin/sestatus

Do you have any iptables firewall rules that may be blocking port 3306?
--
Deron Meranda


Re: mysqldb error

2006-04-13 Thread Firat KUCUK

Hi,
SeLinux is not installed.
iptables output is :

mikropyuvasi:~# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source   destination

Chain FORWARD (policy ACCEPT)
target prot opt source   destination

Chain OUTPUT (policy ACCEPT)
target prot opt source

-

i'll commit suicide :)

i think it is related with:
http://www.modpython.org/FAQ/faqw.py?req=show&file=faq02.013.htp

but i didn't understand.



Re: mysqldb error

2006-04-13 Thread Graham Dumpleton


On 13/04/2006, at 8:33 PM, Firat KUCUK wrote:


i think it is related with:
http://www.modpython.org/FAQ/faqw.py?req=show&file=faq02.013.htp

but i didn't understand.


If that is the case, it is easy to check. This is done by disabling  
the loading

into Apache of PHP support. If after commenting out the PHP lines and
doing a "stop/start" of Apache (best not to use "restart" just in  
case it doesn't

unloaded shared libraries properly) your problem doesn't go away, then
that FAQ entry is not relevant.

Graham


Re: mysqldb error [solved]

2006-04-13 Thread Firat KUCUK

Hi Guys,
php5 uses libmysqlclient12 as default

i made symbolic link like this:

ln -s libmysqlclient.so.14.0.0 libmysqlclient.so.12

problem fixed.
thanks to all.

you are wonderful. ;)




Re: mysqldb error [solved]

2006-04-13 Thread Graham Dumpleton


On 13/04/2006, at 9:30 PM, Firat KUCUK wrote:


Hi Guys,
php5 uses libmysqlclient12 as default

i made symbolic link like this:

ln -s libmysqlclient.so.14.0.0 libmysqlclient.so.12

problem fixed.


I would strongly recommend against doing this as any difference in  
the API or object
layouts will now possibly cause PHP scripts to crash. You really  
should rebuild one
or the other of Python MySQL module or PHP so they have both been  
compiled

against the same version library.

Graham


Re: mysqldb error [solved]

2006-04-13 Thread Fırat KÜÇÜK

Graham Dumpleton yazmış:



On 13/04/2006, at 9:30 PM, Firat KUCUK wrote:


Hi Guys,
php5 uses libmysqlclient12 as default

i made symbolic link like this:

ln -s libmysqlclient.so.14.0.0 libmysqlclient.so.12

problem fixed.



I would strongly recommend against doing this as any difference in  
the API or object
layouts will now possibly cause PHP scripts to crash. You really  
should rebuild one
or the other of Python MySQL module or PHP so they have both been  
compiled

against the same version library.

Graham


yes you are right,
now php mysql connection failed.

thanks.