简体   繁体   中英

command: "from plone import api " producing errors

I am running a Plone instance using the VM Virtual Box. After starting the instance, when I type the import command in the machine: "from plone import api", I get an error: from can't read /var/mail/plone.

I get the same error even if I type: " #!/usr/bin/env python" before the import command

when I rather type python, and then the command : "from plone import api", I get an error: No module named plone.

what should I do?

If you start up the zope site via bin/instance debug it's not clear what plone site should be used, since there can be more than one.

So you first need to define what plone site plone.api should use. This is done by pointing the site manager to your plone site.

./bin/instance debug
Starting debugger (the name "app" is bound to the top-level Zope object)
...
...
>>>
>>> api.portal.get()  # Will not work 
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/path/to/egg/plone.api.egg/plone/api/portal.py", line 82, in get
    'Unable to get the portal object. More info on '
CannotGetPortalError: Unable to get the portal object. More info on http://docs.plone.org/develop/plone.api/docs/api/exceptions.html#plone.api.exc.CannotGetPortalError
>>> plone = app.get('my-plone-site')
>>> plone
<PloneSite at /my-plone-site>
>>> from zope.component.hooks import setSite
>>> setSite(plone)
>>> from plone import api
>>> api.portal.get()
<PloneSite at /my-plone-site>

That's it.

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