Pop and forms and retrieve methods???

Paul Boddie paulb at infercor.no
Mon Mar 20 09:46:02 EST 2000


Akhar wrote:
> 
> Thanks for the pointers they really help. But I've stumbled upon another
> problem that I cannot understand: I use the Cookie.py module and the cgi.py
> module to for Cookie.py store the login and password for future retrieval
> and the cgi.py to use with forms that give out the id of the message I want
> to view. I have a link that looks like http://localhost/mail.py?id=2 and
> then I use the
> try:
>                 form = cgi.FieldStorage()
>                 LField = form["ogin"]
>                 PField = form["pwd"]
>  try:
>                 form = cgi.FieldStorage()
>                 DField = form["id"]
>                 li = DField.value
> finally:
> msd = pop.retrieve(li)

The formatting is rather strange here, but assuming that this is merely a result
of the way your message was posted...

> only to get:
> Traceback (innermost last):
>   File "/var/www/cgi-bin/mail/msg.py", line 42, in ?
>     msd = pop.retrieve(li)
>   File "/usr/local/lib/python1.5/pop.py", line 304, in retrieve
>     data = self.command("RETR %d" % msg)
> TypeError: illegal argument type for built-in operation

Firstly, where does 'msg' come from? Is it taking the value of 'li' in the
function/method call? If so, then...

> I thought at first since my variable was called ID would be conflicting with
> the module but li seems pretty random? What is happening? I also thought it
> might be because the DField.value was incorect but it generates a number and
> not a phrase.

Are you sure that 'li' refers to an integer value? Take a look at this:

>>> print "Horse %d" % "2"
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: illegal argument type for built-in operation
>>> print "Horse %d" % int("2")
Horse 2
>>> 

I can't remember how the 'cgi' module's objects treat numeric values, but I
would suspect that they do no conversions on received field values unless you
somehow specify the kind of conversions you want, or alternatively do them
yourself. The error you get suggests that 'DField.value' is a character string.
Try using the 'int' function as I do in my example, remembering to wrap it in an
appropriate 'try'...'except' block, of course.

Paul



More information about the Python-list mailing list