By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,353 Members | 1,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

Form Post Trouble Using urllib

P: n/a
I'm having trouble posting a form at the USPS web site. I've been
successful using urllib at other sites, but I'm missing why this won't
work:

# begin code
# get zip+4

import urllib

def zip4query():
url = "http://www.usps.com/zip4"
data = {
'Selection': '1',
'urbanization': '',
'firm': '',
'address': '',
'address1': '1600 pennsylvania',
'address2': '',
'city': 'washington',
'state': 'DC',
'zipcode': '',
}
urldata = urllib.urlencode(data)
results = urllib.urlopen(url, urldata).read()
print results

zip4query()

# end code

I just get the query form back as my results. I didn't have this
problem before. What am I doing wrong?

Thanks,
Steve
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
first, the url you should request is
http://www.usps.com/zip4/zip4_response.jsp
it is the "action" attribute of the form submitted as you can see when
you view source of http://www.usps.com/zip4,

then, when you trace javascript executed on the form submission,
you'll notice that the field "address" is filled with the result of
concatenation of "address1" and " " and "address2"

update these two bits and it'll work as you intended
url = "http://www.usps.com/zip4/zip4_response.jsp" .... 'address': '1600 pennsylvania',
'address1': '',
'address2': '',

....

--
bromden[at]gazeta.pl

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.