【问题标题】:MoinMoin 1.9 programmatically creating page error: MoinMoin.PageEditor.AccessDenied: You are not allowed to edit this page!MoinMoin 1.9 以编程方式创建页面错误:MoinMoin.PageEditor.AccessDenied: You are not allowed to edit this page!
【发布时间】:2011-03-11 16:54:39
【问题描述】:

我正在尝试使用 MoinMoin 以编程方式创建一个新的 wiki 页面。但是它不允许我编辑页面,我如何提供用户创建这个页面?

[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!

request 对象上设置User 后,它会创建页面,但随后会锁定整个wiki 实例,无法创建或编辑并保存任何带有401 Unauthorized 错误的新页面。

【问题讨论】:

    标签: python moinmoin


    【解决方案1】:

    您需要获取一个User 并将其附加到ScriptContext 对象,这里称为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)
    

    还有其他方法可以查找User,这对我来说效果很好。我相信有更好的方法。

    警告:确保您以适当的 UID 运行脚本(在我的情况下为 apache:apache),否则您将破坏整个 MoinMoin wiki。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-21
      • 1970-01-01
      • 2016-02-16
      • 2017-03-19
      • 1970-01-01
      • 2016-06-20
      • 2018-02-16
      • 2019-12-15
      相关资源
      最近更新 更多