Skip site navigation (1) Skip section navigation (2)

pl/pyton: exceptions.ImportError: No module named email.Parser

From: Eugene Prokopiev <prokopiev(at)stc(dot)donpac(dot)ru>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: pl/pyton: exceptions.ImportError: No module named email.Parser
Date: 2005-11-27 15:17:06
Message-ID: 4389CDF2.6020805@stc.donpac.ru (view raw or flat)
Thread:
Lists: pgsql-interfaces
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(at)mydomain(dot)com

Why can't I use "import email.Parser" in pl/python function?

--
Thanks,
Eugene Prokopiev

Responses

pgsql-interfaces by date

Next:From: Michael FuhrDate: 2005-11-27 19:34:29
Subject: Re: pl/pyton: exceptions.ImportError: No module named email.Parser
Previous:From: Edoardo InnocentiDate: 2005-11-24 11:07:01
Subject: ERROR CONNECTION POSTGRES 8.1

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group