http POST only returning GET data

vm vinodmap at gmail.com
Fri Jun 24 22:34:06 EDT 2005


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
######################################################




More information about the Python-list mailing list