Tuesday, November 20, 2007

Finished Lab3

The submit process was my greatest difficulty for this lab. I was clueless on how Python gets post variables and a bit confused on the submit script. After talking with Sam, I was able to complete it and was surprised how easy these were.

to get post variables (var1, var2, ...):

def index(req, var1="", var2="", . . . ):

Submitting was a bit more tricky, but I just had to use urlencode(data{}) from the urllib to encode the data dictionary of variables. Then use urllib.urlopen(url, urlencoded(data{})).
docs.python.org has a good example. What confused me was trying to use the http library that someone recommended for doing posts in python.

No comments: