A part of your problem may well be that since you close the socket that you read the page with urllib
with your mechanize session will have a different ID and so require a new token.
You will need to keep a single connection open for the duration of the session. So I think that you will need to parse the contents of the reply to br.read()
to find your value for pwID
.
Comment From OP:
I left out the urllib part and it's working now. I used str(br.form) instead of br.read() though.