[twill] 0.7.3, one site fails in Python, noreadonly patch

Titus Brown titus at caltech.edu
Sun Oct 23 10:52:38 PDT 2005


-> G'day,

Hello!

-> 1.  site fails only in Python script
-> 
-> Using twill-0.7.3 on Python 2.3.5, loading a particular page with a
-> twill script works and showforms recognises the form on the page, but
-> if I try it with a Python script I get an error.  Here's the
-> interactive execution ...

[ munch ]

-> On the other hand, if I do this from twill-sh, it works fine.

[ munch ]

-> Using save_html in both environments shows that the HTML that has been
-> delivered is the same.
-> 
-> I'm afraid I can't provide the HTML or the exact URLs, due to security
-> classification of the content.  But I'm willing to examine program
-> state and so forth if that will help.  I've already tried to dig
-> beneath twill to find out what is going on, but I'm very new to Python
-> and I'm not sure I understand what I see.

That is rather odd; I and several other people have used twill directly
from Python like this w/o a problem.  Looking through the code for
'execute_file' in twill/parse.py, the only two things that are different
are the use of namespaces: in twill, the commands are executed in
specific global/local namespaces.  If used directly from Python, tho,
the commands are executed in the standard Python global/local
namespaces.

One thing you could try is this:

---
from twill.commands import *
from twill import namespaces
namespaces.new_local_dict()
globals_dict, locals_dict = namespaces.get_twill_glocals()

exec 'go("http://www.idyll.org/")' in globals_dict, locals_dict
---

If that doesn't work, I'm truly mystified: you're using exactly the same
commands that twill uses ;).  Let me know...

-> 2.  works great otherwise
-> 
-> I am confident that twill is working fine for other sites.  My first
-> attempt is the attached script, for finding service utilisation on my
-> two-way satellite internet service ... automation of a painfully slow
-> interaction.
-> 
-> An interesting extra step was that the page provided after login
-> contained an HTTP-EQUIV refresh directive with zero timeout.  There
-> didn't seem to be a built-in response to this, so I had to dig in and
-> find the URL from the HTML.

mechanize (the package twill uses for Web browsing) should probably
handle that.  I'll look into it; thanks for letting me know!

-> 3.  readonly controls
-> 
-> One particular curiosity with the bigpond.com site was that the page
-> contains JavaScript that will set the value of a hidden field just
-> before submitting the form.  If it isn't set, then the login fails.
-> 
-> So I patched commands.py to set readonly controls to writable.
-> I figure if JavaScript is allowed to do it, so should twill.

Sounds good to me ;).  I'll add in your patch.

(Your patch is the correct way to do it; I don't want to muck around in
the ClientForm code.)

thanks,
--titus



More information about the twill mailing list