开发者

MoinMoin 1.9 programmatically creating page error: MoinMoin.PageEditor.AccessDenied: You are not allowed to edit this page!

I am trying to create a new wiki page programmatically with MoinMoin. But it is not allowing me to edit the page, how do I provide a user to create this page as?

[Fri Mar 11 11:44:35] [root]开发者_如何学编程@[dev] /usr/local/share/moin
# python2.6
Python 2.6.5 (r265:79063, Jun  4 2010, 21:43:07)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from MoinMoin.web.contexts import ScriptContext
>>> from MoinMoin.PageEditor import PageEditor
>>> request = ScriptContext('http://wiki.dev.itaas.com')
>>> pe = PageEditor(request, 'MyNewTestPage')
>>> pe.saveText('Hello World!', 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/MoinMoin/PageEditor.py", line 1068, in saveText
    raise self.AccessDenied, msg
MoinMoin.PageEditor.AccessDenied: You are not allowed to edit this page!

After setting a User on the request object, it creates the page, but then locks up the entire wiki instance from creating or editing and saving any new pages with 401 Unauthorized errors.


You need to get a User and attach it to the ScriptContext object, here called request.

>>> import MoinMoin.user
>>> user = MoinMoin.user.get_by_email_address(request,'jarrod.roberson@mycompany.com')
>>> request.user = user
>>> pe = PageEditor(request, 'MyNewTestPage')
>>> pe.saveText('Hello World!', 0)

There are other ways to look up a User this one worked well for me. I am sure there is a better way.

WARNING: Make sure you are running your script as the appropriate UID ( in my case apache:apache ) or you will corrupt the entire MoinMoin wiki.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜