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

http POST only returning GET data

P: n/a
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
################################################## ####

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
vm wrote:
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)

--
Benji York

Jul 19 '05 #2

P: n/a
vm
Benji - that worked like a champ - my mistake. thanks

Vinod

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.