app engine post get method. - python

77 views
Skip to first unread message

cloudg

unread,
Aug 19, 2009, 3:24:08 PM8/19/09
to Google App Engine
Hi all,
Iam trying to post data using fetchurl and then use the request
method, i get an error with HTTP 405 code. Both get and post do not
work, but what works is if i hardcode the values in the URL like ?
myhost=cool, it works. Please suggest.


To post data: (y.py)
-------------------------------------------------------------------------------------
from google.appengine.api import urlfetch
from google.appengine.api import apiproxy_stub_map
from google.appengine.api import urlfetch_stub
import urllib

url = "http://myurl/"
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
apiproxy_stub_map.apiproxy.RegisterStub
('urlfetch',urlfetch_stub.URLFetchServiceStub())

form_fields = {
"myhost": "cool",
"mysubject": "aid",
"email_address": "te...@testing.com"
}
form_data = urllib.urlencode(form_fields)
result = urlfetch.fetch(url=url,
payload=form_data,
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-
form-urlencoded'})

-------------------------------------------------------------------------------------
Read data after post (x.py)
-------------------------------------------------------------------------------------
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.api import mail
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
host = self.request.get("myhost")
subj = self.request.get("mysubject")
to_addr = 'te...@tet.com'

application = webapp.WSGIApplication(
[('/', MainPage)],
debug=True)

def main():
run_wsgi_app(application)

if __name__ == "__main__":
main()

Nick Johnson (Google)

unread,
Aug 21, 2009, 6:47:09 AM8/21/09
to google-a...@googlegroups.com
Hi cloudg,

In order to handle POST requests to your handler, you need to define a 'post' method that handles requests of that type. Any HTTP methods that you have not defined handlers for will return a 405 response.

-Nick Johnson
--
Nick Johnson, Developer Programs Engineer, App Engine
Reply all
Reply to author
Forward
0 new messages