0
Plone的外部方法我用這種方式與子POPEN
output = subprocess.Popen("/usr/local/Plone4/zeocluster/products/xxx/Extensions/check_login.py", stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True, cwd='/')
的check_login.py進口,它不是在安裝的模塊有一個調用一個子程序上Plone的外部方法(另一個python腳本) Plone內部的python安裝。這裏有check_login.py的示例代碼:
#!/usr/bin/python
def login_ldap(username, password):
import ldap
conn = ldap.initialize(SERVER_URL)
conn.protocol_version = 3
conn.set_option(ldap.OPT_REFERRALS, 0)
login_ok = False
if username and password:
try:
conn.simple_bind_s(username, password)
login_ok = True
except ldap.INVALID_CREDENTIALS:
pass
return login_ok
if __name__ == '__main__':
import sys
args = sys.argv
if len(args) != 3:
print "Usage: check_login <username> <password>"
else:
username = args[1]
password = args[2]
print login_ldap(username, password),
如果我通過shell調用check_login.py其作品的權利。如果我和裏面的Plone子把它叫做失敗說:
'import site' failed; use -v for traceback
Traceback (most recent call last):
File "/usr/local/Plone4/zeocluster/products/xxxx/Extensions/check_login.py", line 37, in <module>
print login_ldap(username, password),
File "/usr/local/Plone4/zeocluster/products/xxxx/Extensions/check_login.py", line 6, in login_ldap
import ldap
ImportError: No module named ldap
我真的不知道爲什麼check_login.py與Plone中的蟒蛇而不是系統的蟒蛇總是執行。
output = subprocess.Popen([「/ usr/bin/python」,「/ usr/local/Plone4/zeocluster/products/XXXX/Extensions/check_login.py」,member_id,password],stdout = subprocess.PIPE ,stderr = subprocess.PIPE,shell = False) 它仍然返回我同樣的錯誤:(還有我在check_login.py **#!/ usr/bin/python **中更改爲**#!/ usr/bin/env python ** – USSliberty
然後還有其他的東西是錯的,這個問題有什麼問題,當你試圖從命令行運行這個腳本時,它說了什麼? –
我通過SSH進入,輸入「/ usr/local/Plone4/zeocluster/products/xxx/Extensions/check_login.py用戶名密碼「並正常工作。 – USSliberty