I am learning Python and I am trying to do something very simple: send an HTTP POST from one application and get it in another, not only can I not make it work, I cannot make it work with what would seem reasonable using def post (self). This is the code that I have that does not give errors, but does not complete the task: Sender application:
import cgi import webapp2 import urllib import urllib2 import json from google.appengine.api import urlfetch from google.appengine.ext import webapp senddata = {} senddata["message"] = 'Testing the Sender' class MainPagePost(webapp2.RequestHandler): def get(self): txt_url_values = urllib.urlencode(senddata) txturl = 'http://localhost:10080' result = urllib.urlopen(txturl, txt_url_values) self.redirect('http://localhost:10080') application = webapp2.WSGIApplication([ ('/', MainPagePost), ], debug=True)
Receiving application:
import cgi import webapp2 import urllib import urllib2 import json from google.appengine.api import urlfetch from google.appengine.ext import webapp class MainPageGet(webapp2.RequestHandler): def get(self): self.response.write('you sent:') con = self.request.get("message") self.response.write(con) application = webapp2.WSGIApplication([ ('/', MainPageGet), ], debug=True)
All I get on localhost is βyou sent:β :( Worst of all, I donβt understand why both defs should be βget (self)β, so I donβt get 405 error ... Thanks to everyone :)
This is the "new" code, no changes for the sender:
import cgi import webapp2 import urllib import urllib2 import json from google.appengine.api import urlfetch from google.appengine.ext import webapp senddata = {} senddata["message"] = 'Testing Tester' class MainPagePost(webapp2.RequestHandler): def get(self): txt_url_values = urllib.urlencode(senddata) txturl = 'http://localhost:10080' result = urllib.urlopen(txturl, txt_url_values) self.redirect('http://localhost:10080') application = webapp2.WSGIApplication([ ('/', MainPagePost), ], debug=True)
The recipient, I went to the post, as Sam said, but I get 405:
# -*- coding: utf-8 -*- import cgi import webapp2 import urllib import urllib2 import json from google.appengine.api import urlfetch from google.appengine.ext import webapp class MainPageGet(webapp2.RequestHandler): def post(self):
Thanks:)