Code Monkey home page Code Monkey logo

python-dokuwiki's Introduction

python-dokuwiki

Code repo PyPi Documentation Code Health

This python module aims to manage DokuWiki wikis by using the provided XML-RPC API. This module is compatible with python3+.

API is described here.

Release notes

1.3.3 (2022-06-28)

  • Allow slash character in passwords (#26)

1.3.2 (2021-12-03)

  • Correct a bug when using some special characters in the password (c891eb8)

1.3.1 (2021-08-30)

  • Set default empty value for summary to structs.get_data()
  • Add minor parameter to structs.get_data()

1.2.1 (2019-07-24)

  • Remove login call in the constructor as it seems to fail on some cases (98ed799).

1.2.0 (2019-06-25)

  • Support of HTTPS for cookie based authentication.

1.1.0 (2018-03-22)

  • Support authentication by cookie (thanks to luminisward).

1.0.1 (2017-04-06)

  • Correct a typo with an exception call.

1.0 (2017-04-06)

  • Prevent username and password to be passed as GET parameters (e4cbb5d).

0.5 (2016-08-19)

  • Correct a bug when retrieving/uploading medias (a1f56b6).

0.4 (2016-02-07)

0.3 (2015-08-16)

  • The xmlrpc parameter use_datetime is no longer forced to True by default (bec3447). This may break things!

0.2 (2014-01-29)

  • Manage dataentries (this is a plugin for managing metadatas).

0.1 (2014-01-29)

  • Implement DokuWiki XML-RPC commands.
  • Compatible with both python 2 and 3.

python-dokuwiki's People

Contributors

a-detiste avatar alexdraconian avatar atnbueno avatar fmenabe avatar glensc avatar gschnellonera avatar jeltef avatar luminisward avatar rsingh avatar tokas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

python-dokuwiki's Issues

CookiesTransport only supports HTTP, not HTTPS

CookiesTransport is a subclass of Transport (HTTP), not of SafeTransport (HTTPS).
Therefore, even if the wiki URL contains "https://", only an unsecured HTTP connection is created for XMLRPC calls if the user chooses cookie authentication.
On a server that redirects all HTTP traffic to HTTPS, the XMLRPC call receives a 301 (permanent redirect) response that it does not know how to handle.
This results in an exception: xmlrpc.client.ProtocolError: <ProtocolError for example.com/lib/exe/xmlrpc.php: 301 Moved Permanently>.

I guess the best option would be to add a SafeCookiesTransport(SafeTransport) class that is used as transport if the url starts with "https://".

Python 2.7 xmlrpclib

with the small example code from the https://pypi.python.org/pypi/dokuwiki/0.2 i get following error.
( think it a python3 to python2.7 problem within)

File "C:\Anaconda\lib\xmlrpclib.py", line 1391, in send_request
connection.putrequest("POST", handler, skip_accept_encoding=True)
AttributeError: 'NoneType' object has no attribute 'putrequest'

shows not all articles

wiki.pages.list() shows only articles for everyone, but I have articles with access for users(administrators).

I specify the (admin)username and password in wiki = DokuWiki('http://192.168.1.11/dokuwiki', 'myyuser', 'mypwd'), but get the list, like without a login and password.

uploading images fails

Hi,

I'm using python-dokuwiki 0.4.0-5-gfc55e58 with dokuwiki 2016-06-26a "Elenor of Tsort".
When uploading image files (png, jpg) I get this error message, no matter if I run wiki.medias.set or wiki.medias.add:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/dokuwiki.py", line 362, in add
    Binary(fhandler.read()), ow=overwrite)
  File "/usr/local/lib/python2.7/dist-packages/dokuwiki.py", line 113, in send
    raise DokuWikiError(err)
dokuwiki.DokuWikiError: <Fault 1: 'The uploaded content did not match the .png file extension.'>

PDF files work fine and I can upload images from the web interface.

When it comes to getting media from dokuwiki, this time for both images and pdf, I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/dokuwiki.py", line 337, in get
    data = b64decode(data)
  File "/usr/lib/python2.7/base64.py", line 73, in b64decode
    return binascii.a2b_base64(s)
TypeError: must be string or buffer, not instance

There is a similar report here for perl, so maybe there's a similar solution for python.

Thanks, Dennis

cookie auth doesn't work with HTTPS

My wiki requires cookieAuth, but also is served via HTTPS. Since CookieTransport always inherits from xmlrpclib's Transport, not SafeTransport, this is not possible right now.

When patched to use SafeTransport as a base class, it works fine for HTTPS for me (py2 and py3 variants). So either you need four classes, or a more intelligent switch :)

Thanks!

Login problems

Hi,
I'm having some problems logging in. To be as specific as I can be at the moment:

  • I've created a user, with the same password, for test purposes;
  • I've created the group api, and added the user to it;
  • I've activated XPC;
  • I've added both the user and the group in the remoteuserparam; I've also tried to leave it empty to give acess to everyone;
  • I'm accessing through the https url.

Example code (WIKI_URL, username and password are hardcoded a few lines before and have been double checked):

import dokuwiki

v = dokuwiki.DokuWiki(WIKI_URL, username, password).xmlrpc_version()
print(v)

The output is:

Traceback (most recent call last):
  File "/Users/manuellevi/PycharmProjects/deleteme/get_wiki_stats.py", line 5, in <module>
    wiki = dokuwiki.DokuWiki(WIKI_URL, username, password).xmlrpc_version()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/dokuwiki.py", line 169, in __init__
    raise DokuWikiError('invalid login or password!')
dokuwiki.DokuWikiError: invalid login or password!

Having checked the URL, username and password, could I be missing something?
I'm wondering if I misread something in the docs.

EDIT: running this with python3 get_wiki_version.py.

Thanks,
ML

typing annotation

Hi,

Would you accept a PR that removes Py2 support and add typing annotations ?

It helps ensure that python-dokuwiki users call it with the right parameters.

Do not pass login credentials via urlparameters - use BasicAuth instead

To avoid passing username & password as GET parameters, having them plaintext in server logs I added the ability to use HTTP BasicAuth. Tested only with py3.

class BasicAuthTransport(xmlrpc.client.SafeTransport):
	def __init__(self, username, password):
		super().__init__()
		self._auth = base64.encodestring('{}:{}'.format(username, password).encode('ascii'))[:-1].decode('ascii')

	def send_headers(self, connection, headers):
		connection.putheader("Authorization", "Basic {}".format(self._auth))
		super().send_headers(connection, headers)


class DokuWiki(dokuwiki.DokuWiki):
	def __init__(self, url, user, password):
		t = BasicAuthTransport(user, password)
		self.proxy = xmlrpc.client.ServerProxy("{url}/lib/exe/xmlrpc.php".format(url=url), transport=t)
		if not self.login(user, password):
			raise DokuWikiError('invalid login or password!')

		# Set "namespaces" for pages and medias functions.
		self.pages = dokuwiki._Pages(weakref.ref(self)())
		self.medias = dokuwiki._Medias(weakref.ref(self)())

ProtocolError 412 Precondition Failed

Hi,
I get this error message in 3 different Dokuwiki sites when I try to create a new connection:

wiki = dokuwiki.DokuWiki('HTTPS-URL','USER','PASSWORD')
Traceback (most recent call last):
File "", line 1, in
File "/home/user/PycharmProjects/test/venv/lib/python3.7/site-packages/dokuwiki.py", line 173, in init
self.version
File "/home/user/PycharmProjects/test/venv/lib/python3.7/site-packages/dokuwiki.py", line 210, in version
return self.send('dokuwiki.getVersion')
File "/home/user/PycharmProjects/test/venv/lib/python3.7/site-packages/dokuwiki.py", line 196, in send
return method(*args)
File "/usr/lib/python3.7/xmlrpc/client.py", line 1112, in call
return self.__send(self.__name, args)
File "/usr/lib/python3.7/xmlrpc/client.py", line 1452, in __request
verbose=self.__verbose
File "/usr/lib/python3.7/xmlrpc/client.py", line 1154, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python3.7/xmlrpc/client.py", line 1187, in single_request
dict(resp.getheaders())
xmlrpc.client.ProtocolError: <ProtocolError for USER:PASSWORD@HTTPS-URL/lib/exe/xmlrpc.php: 412 Precondition Failed>

Thanks, Jose

xml rpc error on the response.

Heya,

I am trying to use this to interact with my dokuwiki but I am getting a response error, I wondered if you have any ideas about where to start debugging it. Code samples below:

import dokuwiki import ssl gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1) wiki = dokuwiki.DokuWiki('https://10.3.5.251/', 'user', 'pass',context=gcontext)

Python 2 response:
File "/usr/lib/python2.7/xmlrpclib.py", line 798, in close raise ResponseError() xmlrpclib.ResponseError: ResponseError()
Python 3 response
File "/usr/lib/python3.6/xmlrpc/client.py", line 656, in close raise ResponseError() xmlrpc.client.ResponseError: ResponseError()

I also tried
`
from xmlrpclib import ServerProxy
from urllib import urlencode
import ssl

URL = 'https://10.3.5.251/'
USER = 'asdf'
PWD = "asdf"
gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
url = '%s/lib/exe/xmlrpc.php?%s' % (URL, urlencode({'u': USER, 'p': PWD}))
proxy = ServerProxy(url,context=gcontext)
print(proxy.dokuwiki.getVersion())
`
And got the same responses.
Is there another arg I need to pass in to get the responses in the correct format?
Doing it manually in a proxy I get a valid xml response

Content-Type: text/xml; charset=utf-8

`

1 `

Trying to add medias throws "dokuwiki.DokuWikiError: <Fault 1: "You don't have permissions to upload files.">"

This worked last month but I just moved to a new laptop and now am getting the below traceback... tried figuring out XML-RCP config but have had no luck; I didn't have to do this on my old PC so am wondering what went wrong in moving.

I'm running PHP 7.3.33 and have if(!$conf['remote']) die((new IXR_Error(-32605, "XML-RPC server not enabled."))->getXml()); in my xmlrpc.php file

Traceback (most recent call last):
  File "C:\Users\PycharmProjects\MiscTools\venv\Lib\site-packages\dokuwiki.py", line 197, in send
    return method(*args)
           ^^^^^^^^^^^^^
  File "C:\Python311\Lib\xmlrpc\client.py", line 1122, in __call__
    return self.__send(self.__name, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\xmlrpc\client.py", line 1464, in __request
    response = self.__transport.request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\xmlrpc\client.py", line 1166, in request
    return self.single_request(host, handler, request_body, verbose)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\xmlrpc\client.py", line 1182, in single_request
    return self.parse_response(resp)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\xmlrpc\client.py", line 1354, in parse_response
    return u.close()
           ^^^^^^^^^
  File "C:\Python311\Lib\xmlrpc\client.py", line 668, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 1: "You don't have permissions to upload files.">

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\PycharmProjects\MiscTools\dokuwikiproject.py", line 30, in <module>
    wiki.medias.add('wiki:' + file, file, overwrite=True)
  File "C:\Users\\PycharmProjects\MiscTools\venv\Lib\site-packages\dokuwiki.py", line 452, in add
    self._dokuwiki.send('wiki.putAttachment', media,
  File "C:\Users\\PycharmProjects\MiscTools\venv\Lib\site-packages\dokuwiki.py", line 203, in send
    raise DokuWikiError(err)
dokuwiki.DokuWikiError: <Fault 1: "You don't have permissions to upload files.">

error on using some special chars in password

I get this error when trying to create an instance of the client

Traceback (most recent call last):
  File "/usr/lib/python3.8/http/client.py", line 868, in _get_hostport
    port = int(host[i+1:])
ValueError: invalid literal for int() with base 10: 'R'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "fillDokuWikiPage.py", line 72, in <module>
    run(args.config)
  File "fillDokuWikiPage.py", line 39, in run
    dokuwikiClient = RemoteDokuWikiClient('http://172.19.0.3',
  File "/home/jack/test/lib/dokuwiki/remoteDokuWikiClient.py", line 8, in __init__
    self.client = dokuwiki.DokuWiki(url, username, passwd)
  File "/home/jack/test/env/lib/python3.8/site-packages/dokuwiki.py", line 173, in __init__
    self.version
  File "/home/jack/test/env/lib/python3.8/site-packages/dokuwiki.py", line 211, in version
    return self.send('dokuwiki.getVersion')
  File "/home/jack/test/env/lib/python3.8/site-packages/dokuwiki.py", line 197, in send
    return method(*args)
  File "/usr/lib/python3.8/xmlrpc/client.py", line 1109, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python3.8/xmlrpc/client.py", line 1450, in __request
    response = self.__transport.request(
  File "/usr/lib/python3.8/xmlrpc/client.py", line 1153, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python3.8/xmlrpc/client.py", line 1165, in single_request
    http_conn = self.send_request(host, handler, request_body, verbose)
  File "/usr/lib/python3.8/xmlrpc/client.py", line 1266, in send_request
    connection = self.make_connection(host)
  File "/usr/lib/python3.8/xmlrpc/client.py", line 1243, in make_connection
    self._connection = host, http.client.HTTPConnection(chost)
  File "/usr/lib/python3.8/http/client.py", line 830, in __init__
    (self.host, self.port) = self._get_hostport(host, port)
  File "/usr/lib/python3.8/http/client.py", line 873, in _get_hostport
    raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
http.client.InvalidURL: nonnumeric port: 'R'

credentials are:

  • username: bot
  • password: R#IZM#@tf^93Vz3GKS§C

I reduced the problem to that, due the fact that if I remove '#' and '^' and '@' of the password and set this in the wiki it is working.

Simple Login doesnt work

import dokuwiki

try:
    url = "http://my.page.com/dokuwiki"
    nick = "myname"
    pwd = "mypwd"
    wiki = dokuwiki.DokuWiki(url, nick, pwd)
    html = wiki.pages.html('start')
    print(html)

except (dokuwiki.DokuWikiError, Exception) as err:
    print('unable to connect: %s' % err)

gives me Exception

unable to connect: invalid login or password!

while

from xmlrpc.client import ServerProxy
from urllib.parse import urlencode

URL = "http://my.page.com/dokuwiki"
USER = "myname"
PWD = "mypwd"

url = '%s/lib/exe/xmlrpc.php?%s' % (URL, urlencode({'u': USER, 'p': PWD}))
proxy = ServerProxy(url)
print(proxy.dokuwiki.getVersion())
# should print something like: Release 2018-04-22b "Greebo"

for x in proxy.dokuwiki.search('start'):
    print(x["snippet"])
    break

does everything i want...

Any idea what this could be?

ImportError: No module named docuwiki

Hi François,

this module could be very useful.

I installed the module via:

pip install docuwiki

and through the pip list I check the installation.

I then used tried to import the module but I get this error:

# python
Python 2.7.5 (default, Jun 20 2019, 20:27:34)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import docuwiki
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named docuwiki
>>>

Can you help me to solve this?

Thanks,
Sara

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.