简体   繁体   中英

How to login to BaseX using Python?

How do I login to BaseX as below:

nicholas : 
nicholas : basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
> 
> show users
Username  Permission  
--------------------
admin     admin       
nicholas  none        

2 user(s).
> 
> password
Password: 
Password of user 'admin' changed.
> 
> xquery user:list-details()[@name = 'admin'] 
<user name="admin" permission="admin">
  <password algorithm="digest">
    <hash>hjklhjkhj</hash>
  </password>
  <password algorithm="salted-sha256">
    <salt>jkljlkjkljl</salt>
    <hash>jljkljkljl</hash>
  </password>
</user>
Query executed in 235.21 ms.
> 
> exit
Have fun.
nicholas : 
nicholas : python3 basex.py 
Traceback (most recent call last):
  File "basex.py", line 4, in <module>
    session = BaseXClient.Session('localhost', 1984, 'admin', 'jljljkl')
  File "/usr/local/lib/python3.8/dist-packages/BaseXClient/BaseXClient.py", line 116, in __init__
    self.__swrapper.connect((host, port))
  File "/usr/local/lib/python3.8/dist-packages/BaseXClient/BaseXClient.py", line 92, in <lambda>
    return lambda *arg, **kw: getattr(self.__s, name)(*arg, **kw)
ConnectionRefusedError: [Errno 111] Connection refused
nicholas : 

using sample Python as:

from BaseXClient import BaseXClient
from parsel import Selector

session = BaseXClient.Session('localhost', 1984, 'admin', 'jkljkljlk')

print(session.info())

   # create new database

session.create("database", "<x>Hello World!</x>")

print(session.info())



    # run query on database

print("\n" + session.execute("xquery doc('database')"))

    # drop database
 #   session.execute("drop db database")

print(session.info())

#finally:
    # close session

if session:
    session.close()

I can only reset the password so many times.

Perhaps this won't work from standalone mode?

https://docs.basex.org/wiki/Database_Server

says:

Server

The database server handles concurrent read and write transactions, manages user permissions and logs user interactions. It can be started as follows:

 Run one of the basexserver or basexserver.bat scripts. Add the stop keyword to gracefully shut down the server. If you have installed BaseX on Windows, click on the BaseX HTTP Server (Start) icon, which will start both the HTTP Server used for

Web Applications and the database server. With BaseX HTTP Server (Stop), you can shut down the server process.

By default, the server listens to the port 1984. Pressing Ctrl+c will close all connections and databases and gracefully shut down the server process.

Various command-line options are available to simplify batch processing. The start script can be adjusted for individual purposes (eg if the default memory limit is too restrictive).

You need to have basexserver running in order to connect to it with the client API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM