从正在从.procmailrc文件调用的python脚本进行HTTP调用时,我遇到了一个问题。你能提出一个如何解决它的方法吗?我没有选择任何选择。从命令行运行相同的脚本时,HTTP调用正常工作。 以下是详细信息:
.procmailrc内容: DEFAULT = $ HOME / Maildir的/ MAILDIR = $ HOME / Maildir的 PMDIR = $ HOME / .procmail LOGFILE = / home / prasad / log.'date +%y-%m-%d' SHELL = /斌/庆典 VERBOSE = YES
:0
| /usr/bin/python /home/prasad/test.py >>/tmp/py_log.txt
从命令行运行时它可以建立网络连接。
test.py的内容:
url="http://server/book"
post_params = {
'foo' : 'bar'
}
params = urllib.urlencode(post_params)
response = urllib2.urlopen(url, params)
print "after urlopen"
json_response = json.loads(response.read())
它挂在'response = urllib2.urlopen(url,params)'并且从未看到打印“在urlopen之后”调用。
编辑: 我刚刚在procmail生成的日志文件中发现权限错误。 procmailrc在非root帐户下运行。如何解决?
procmail: Executing " /usr/bin/python /home/prasad/test.py >>/tmp/py_log.txt"
Traceback (most recent call last):
File "/home/prasad/test.py", line 23, in <module>
response = urllib2.urlopen(url, params)
File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib64/python2.6/urllib2.py", line 391, in open
response = self._open(req, data)
File "/usr/lib64/python2.6/urllib2.py", line 409, in _open
'_open', req)
File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib64/python2.6/urllib2.py", line 1190, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib64/python2.6/urllib2.py", line 1165, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 13] Permission denied>