Offlineimap 运行 with launchd 找不到 python 用于隐藏密码的模块
Offlineimap run with launchd can't find python modules used to hide password
我正在尝试使用 launchd 在 OSX El Capitan 的后台将 offlineimap 变为 运行。
这是我的 plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.andypierz.offlineimap.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/offlineimap</string>
<string>-u</string>
<string>quiet</string>
</array>
<key>StartInterval</key>
<integer>60</integer>
<key>StandardErrorPath</key>
<string>/Users/Andy/.Mailder/offlineimap_err.log</string>
<key>StandardOutPath</key>
<string>/Users/Andy/.Mailder/offlineimap.log</string>
</dict>
</plist>
这会加载并 运行s,但是我的日志显示 offlineimap 运行正在出错:
OfflineIMAP 6.7.0
Licensed under the GNU GPL v2 or any later version (with an OpenSSL exception)
ERROR: No module named keyring
ERROR: Exceptions occurred during the run!
ERROR: No module named keyring
为了避免在我的 .offlineimaprc 中使用明文密码,我使用 python 密钥环方法 here。
当我从终端 运行 offlineimap 时,它工作正常,我可以使用 python 密钥环毫无问题地导入我的密码。同样,当我 运行 offlineimap 作为 cronjob 时,这似乎也能正常工作。但是,cron 在 OSX 上已被弃用,因此我更愿意使用 launchd。
我的 .offlineimaprc 的相关部分:
[general]
accounts = personal, work
maxsyncaccounts = 3
pythonfile = /Users/Andy/offlineimap.py
[Repository personalRemote]
type = IMAP
remotehost = myhost.com
remoteuser = myalperson@email.com
remotepasseval = keyring.get_password('email', 'personal')
[Repository workRemote]
type = IMAP
remotehost = myhost.com
remoteuser = mywork@email.com
remotepasseval = keyring.get_password('email', 'work')
我的 offlineimap.py 文件只是
#!/usr/bin/python
import keyring
回答错误:
$sudo pip install keyring
如果这对你不起作用,
0) 像完成一样在钥匙串中创建密码 here in Retrieving Passwords section
1) 创建文件
$touch ~/offlineimap.py
offlineimap.py
#!/usr/bin/python
import re, subprocess
def get_keychain_pass(account=None, server=None):
params = {
'security': '/usr/bin/security',
'command': 'find-internet-password',
'account': account,
'server': server,
'keychain': '/Users/${USER}/Library/Keychains/login.keychain',
}
command = "sudo -u ${USER} %(security)s -v %(command)s -g -a %(account)s -s %(server)s %(keychain)s" % params
output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
outtext = [l for l in output.splitlines()
if l.startswith('password: ')][0]
return re.match(r'password: "(.*)"', outtext).group(1)
2) 在
中编辑行
.offlineimaprc
pythonfile = ~/offlineimap.py
3) 并更新远程部分
remotepasseval = get_keychain_pass(account="testUser@company.com", server="sub.domain.com")
4) 如果还有问题,尝试将offlineimap.py文件中的命令参数改为
find-generic-password
5) 更正您的 标签字符串 和 运行 它在开始时仅一次
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.andypierz.offlineimap</string>
<key>LaunchOnlyOnce</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>/usr/local/bin/offlineimap -u quiet</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
6) 加载它
launchctl load com.andypierz.offlineimap.plist
我正在尝试使用 launchd 在 OSX El Capitan 的后台将 offlineimap 变为 运行。
这是我的 plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.andypierz.offlineimap.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/offlineimap</string>
<string>-u</string>
<string>quiet</string>
</array>
<key>StartInterval</key>
<integer>60</integer>
<key>StandardErrorPath</key>
<string>/Users/Andy/.Mailder/offlineimap_err.log</string>
<key>StandardOutPath</key>
<string>/Users/Andy/.Mailder/offlineimap.log</string>
</dict>
</plist>
这会加载并 运行s,但是我的日志显示 offlineimap 运行正在出错:
OfflineIMAP 6.7.0
Licensed under the GNU GPL v2 or any later version (with an OpenSSL exception)
ERROR: No module named keyring
ERROR: Exceptions occurred during the run!
ERROR: No module named keyring
为了避免在我的 .offlineimaprc 中使用明文密码,我使用 python 密钥环方法 here。
当我从终端 运行 offlineimap 时,它工作正常,我可以使用 python 密钥环毫无问题地导入我的密码。同样,当我 运行 offlineimap 作为 cronjob 时,这似乎也能正常工作。但是,cron 在 OSX 上已被弃用,因此我更愿意使用 launchd。
我的 .offlineimaprc 的相关部分:
[general]
accounts = personal, work
maxsyncaccounts = 3
pythonfile = /Users/Andy/offlineimap.py
[Repository personalRemote]
type = IMAP
remotehost = myhost.com
remoteuser = myalperson@email.com
remotepasseval = keyring.get_password('email', 'personal')
[Repository workRemote]
type = IMAP
remotehost = myhost.com
remoteuser = mywork@email.com
remotepasseval = keyring.get_password('email', 'work')
我的 offlineimap.py 文件只是
#!/usr/bin/python
import keyring
回答错误:
$sudo pip install keyring
如果这对你不起作用,
0) 像完成一样在钥匙串中创建密码 here in Retrieving Passwords section
1) 创建文件
$touch ~/offlineimap.py
offlineimap.py
#!/usr/bin/python
import re, subprocess
def get_keychain_pass(account=None, server=None):
params = {
'security': '/usr/bin/security',
'command': 'find-internet-password',
'account': account,
'server': server,
'keychain': '/Users/${USER}/Library/Keychains/login.keychain',
}
command = "sudo -u ${USER} %(security)s -v %(command)s -g -a %(account)s -s %(server)s %(keychain)s" % params
output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
outtext = [l for l in output.splitlines()
if l.startswith('password: ')][0]
return re.match(r'password: "(.*)"', outtext).group(1)
2) 在
中编辑行.offlineimaprc
pythonfile = ~/offlineimap.py
3) 并更新远程部分
remotepasseval = get_keychain_pass(account="testUser@company.com", server="sub.domain.com")
4) 如果还有问题,尝试将offlineimap.py文件中的命令参数改为
find-generic-password
5) 更正您的 标签字符串 和 运行 它在开始时仅一次
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.andypierz.offlineimap</string>
<key>LaunchOnlyOnce</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>/usr/local/bin/offlineimap -u quiet</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
6) 加载它
launchctl load com.andypierz.offlineimap.plist