http POST only returning GET data

V

vm

Hi, for some reason my POST is not working properly. I am basically
just trying to get a simple stock quote from yahoo by posting the
ticker symbol (GE as an example) into finance.yahoo.com. However, when
I POST, I do get a response back, but it is just the main page
finance.yahoo.com and it doesn't seem as if the POST got through. I am
using Python 2.2. I get a status and reason of 200 and OK
respectively. I've searched through these groups on previous POST
problems, but none have seemed to help so far. Any help would be
greatly appreciated, or if there is a previous post that describes this
same problem, please let me know.

In addition, when I change the headers from back and forth between
"multipart/form-data" and "application/x-www-form-urlencoded", there
seems to be no change. How do I know which Content-type to use for
each page. When I look at the Content-type on the yahoo page, it says
"text/html; charset=iso-8859-1" -- but if I enter this in, I get other
errors. How do I know which Content-type to use when I pass it as
headers?

Thank you very much.

######################################################
import urllib,httplib

url = "finance.yahoo.com"
fields = { "s": "ge" }
params = urllib.urlencode(fields)
##headers = {"Content-type": "application/x-www-form-urlencoded",
## "Accept":"text/plain"}
headers = {"Content-type": "multipart/form-data",
"Accept":"text/plain"}

httpSess = httplib.HTTPConnection(url)
httpSess.request("POST","/",params,headers)

response = httpSess.getresponse()

print "status=%s, reason=%s" % (response.status,response.reason)

data = response.read()

print "OUTPUT = \n\n%s\n\n" % data
######################################################
 
B

Benji York

vm said:
Hi, for some reason my POST is not working properly.

Look at the URL again, you missed a character. You had:

httpSess.request("POST","/",params,headers)

It should be:

httpSess.request("POST","/q",params,headers)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top