From: Eugene Prokopiev <prokopiev@stc.donpac.ru>
To: pgsql-interfaces@postgresql.org
Subject: pl/pyton: exceptions.ImportError: No module named email.Parser
Date: Sun, 27 Nov 2005 18:17:06 +0300
Message-ID: <4389CDF2.6020805@stc.donpac.ru> (raw)
Hi,
I need to parse e-mail messages in pl/python functions. So, I write:
dbmail=# create or replace function get_header(varchar) returns varchar
as $$
dbmail$# import email.Parser
dbmail$# parser = email.Parser.Parser()
dbmail$# message = parser.parse(args[0])
dbmail$# return message.get("From")
dbmail$# $$ language plpythonu;
CREATE FUNCTION
dbmail=#
dbmail=# select get_header(messageblk) from dbmail_messageblks;
ERROR: plpython: function "get_header" failed
DETAIL: exceptions.ImportError: No module named email.Parser
Simple pl/python functions works fine:
dbmail=# create or replace function test(varchar) returns varchar as $$
dbmail$# return args[0]
dbmail$# $$ language plpythonu;
CREATE FUNCTION
dbmail=#
dbmail=# select test('test');
test
------
test
(1 record)
Message parsing with standalone python works too:
$ cat mail.py
import sys
import email.Parser
parser = email.Parser.Parser()
message = parser.parse(sys.stdin)
print message.get("From")
$ python mail.py < mbox
test@mydomain.com
Why can't I use "import email.Parser" in pl/python function?
--
Thanks,
Eugene Prokopiev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: prokopiev@stc.donpac.ru
Subject: Re: pl/pyton: exceptions.ImportError: No module named email.Parser
In-Reply-To: <4389CDF2.6020805@stc.donpac.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox