Home > Uncategorized > A HTTP Proxy in Python for Google AppEngine

A HTTP Proxy in Python for Google AppEngine

Labnol’s AppEngine Proxy is useful for viewing other pages requested via Google AppEngine, however, it does change the HTML, and doesn’t handle POST data. This is a code example in Google AppEngine Python showing how to implement a HTTP proxy in a similar way to Labnol.

from google.appengine.ext import webapp
from google.appengine.ext.webapp import util

import urllib2
import urllib
import re
import array
import urllib2


class MainHandler(webapp.RequestHandler):
	def get(self):	
		#self.response.out.write('[GET] The URL Requested was ' + self.request.query_string)
		response = urllib2.open(self.request.query_string)
		html = response.read()
		self.response.out.write(html)

	def post(self):	
		#self.response.out.write('[POST] The URL Requested was ' + self.request.query_string + "
") args = self.request.arguments() strPostdata = "" for arg in args: strPostdata = strPostdata + arg + "=" + self.request.get(arg) + "&" #self.response.out.write("[POST] The data was:" + strPostdata) request = urllib2.Request(self.request.query_string) request.add_data(str(strPostdata)) response = urllib2.urlopen(request) html = response.read() self.response.out.write(unicode(html,"latin1")) def main(): application = webapp.WSGIApplication([('/', MainHandler)], debug=True) util.run_wsgi_app(application) if __name__ == '__main__': main()
Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: