如何使用Python登录BaseX?

How to login to BaseX using Python?

如何登录 BaseX,如下所示:

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 : 

使用 sample Python 作为:

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()

我只能重设密码这么多次

也许这在 standalone 模式下不起作用?

https://docs.basex.org/wiki/Database_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 (e.g. if the default memory limit is too restrictive).

您需要有 basexserver 运行 才能与客户端连接 API。