MonetDB / pymonetdb

The Python API for MonetDB
https://www.monetdb.org/
Mozilla Public License 2.0
28 stars 20 forks source link

can't use Control #23

Closed dfroger closed 7 years ago

dfroger commented 7 years ago

This may not be a bug, but I can't understand what I'm doing wrong. (Tested with Python 2.7 and 3.6).

Creating a farm, a database, and populating it works:

export DOTMONETDBFILE="monetdb_config"

cat << EOF > $DOTMONETDBFILE
user=monetdb
password=monetdb
EOF

monetdbd create dbfarm
monetdbd start dbfarm

monetdb create demo
monetdb start demo

echo "CREATE TABLE names (id integer,name varchar(20));" | mclient -d demo
echo "INSERT INTO names VALUES (0, 'Alice');" | mclient -d demo
echo "INSERT INTO names VALUES (1, 'Bob');" | mclient -d demo
echo "SELECT * FROM names;" | mclient -d demo

Querying the database in Python works:

import pymonetdb

connection = pymonetdb.connect(username="monetdb", password="monetdb",
                               hostname="localhost", database="demo")

cursor = connection.cursor()

cursor.execute('SELECT * FROM names')
cursor.fetchall()

But I always get access denied when trying to use Control:


import pymonetdb.control
pymonetdb.control.Control(passphrase='monetdb', hostname='localhost')

No handlers could be found for logger "pymonetdb.mapi"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "(...)/lib/python2.7/site-packages/pymonetdb/control.py", line 91, in __init__
    unix_socket=unix_socket)
  File "(...)/lib/python2.7/site-packages/pymonetdb/mapi.py", line 142, in connect
    self._login()
  File "(...)/lib/python2.7/site-packages/pymonetdb/mapi.py", line 165, in _login
    raise DatabaseError(prompt[1:])
pymonetdb.exceptions.DatabaseError: access denied

Thanks!

Note: same error with:

pymonetdb.control.Control(passphrase='monetdb', hostname=None)
dfroger commented 7 years ago

Simplify it a bit, this works (this is how pymonetdb.connect invokes mapi):

server = mapi.Connection()

server.connect(hostname=None, port=50000, username='monetdb',
               password='monetdb',
               database='demo', language='sql',
               unix_socket='/tmp/.s.merovingian.50000')

this fails with access denied (this is how pymonetdb.control.Control invokes mapi):

server = mapi.Connection()

server.connect(hostname='localhost', port=50000, username='monetdb',
               password='monetdb',
               database='merovingian', language='control',
               unix_socket='/tmp/.s.merovingian.50000')
gijzelaerr commented 7 years ago

you you need to set a passphrase for monetdbd, enable remote management restart it.

this is unrelated to the authentication per database.

https://www.monetdb.org/Documentation/monetdbd-man-page

dfroger commented 7 years ago

Thanks for the response. As monetdb create demo command line tool was working, I was thinking the Python API could work the same way.

dfroger commented 7 years ago

ok, that works! thanks again for the help!

gijzelaerr commented 7 years ago

it should be able to work over a socket without authentication, i never got to it to implement that since the protocol is slightly different. I think I documented it somewhere, but probably it is not obvious enough.