473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Form Post Trouble Using urllib

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
1 6940
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: franck | last post by:
HI, this is my code params = {} params = '*****'; params = '***'; params = '**********'; params = '******'; params = '****';
8
by: bmgx | last post by:
I would like to use an already existing online service (currency converter) basically consisting of a html form with a few options that is submitted and returns the results. I really don't know...
0
by: Pieter Edelman | last post by:
Hi all, I'm trying to submit some data using a POST request to a HTTP server with BASIC authentication with python, but I can't get it to work. Since it's driving me completely nuts, so here's...
2
by: jponiato | last post by:
Greetings. An HTML form submits it's data to a python cgi script on my server. This script accepts this POST data, and uses urllib.urlopen() to call a different cgi script (on an external server),...
11
by: livin | last post by:
I need to post form data to an ASP page that looks like this on the page itself... <form method='POST'><input src=\icons\devices\coffee-on.gif type='image' align='absmiddle' width=16 height=16...
1
by: evanpmeth | last post by:
I am currently working a program that was intended to be purely JS and AJAX. Due to the cross domain access problems i have defaulted to a language I enjoy more, Python. My project consists of a...
10
by: Sulsa | last post by:
I need to fill form from web site, the code for this form looks like this: <form action="login.php" method="post" target="_top"> <input type="text" name="username" size="25" maxlength="40"...
0
Thekid
by: Thekid | last post by:
I'm trying to auto send a form submission to a website but it isn't working. I've done this before and it worked but for some reason, using the same basic code, it doesn't seem to submit it. I'm...
4
SuperMetroid
by: SuperMetroid | last post by:
The html code of the form, and my code are below. I can't get the value to post/submit.. instead I get an error. Can anyone help? HTML Code of Form: <form method='post' autocomplete='off'> ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.