1

从 .procmailrc 文件调用的 python 脚本进行 HTTP 调用时,我遇到了一个问题。您能否提出一种解决方法?我用完了所有选项。当从命令行运行相同的脚本时,HTTP 调用工作正常。以下是详细信息:

.procmailrc 内容:DEFAULT=$HOME/Maildir/MAILDIR=$HOME/Maildir PMDIR=$HOME/.procmail LOGFILE=/home/prasad/log.'date +%y-%m-%d' SHELL=/bin/ bash 详细=是

: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>
4

0 回答 0