Forcing a HTTP Proxy on Local Google App Engine Development Server

I’ve been trying somewhat in vain to debug a REST interface that’s failing when running under GAE. After some searching, I found a way to force the local development server to use an http proxy (such as Charles or Membrane).

Make the following changes in the file:

C:\Program Files\Google\google_appengine\google\appengine\api\urlfetch_stub.py

around line 193:

      
<pre>
try:
    if protocol == 'http':         
        logging.debug("using proxy instead of %s path=%s", host, path)  
        connection = httplib.HTTPConnection("127.0.0.1", 8888)   # host and port of proxy server
        path = "http://%s%s"%(host,path)
        logging.debug("new path is: '%s'", path)
    elif protocol == 'https':
          connection = httplib.HTTPSConnection(host)
    else:
        error_msg = 'Redirect specified invalid protocol: "%s"' % protocol
        logging.error(error_msg)
        raise apiproxy_errors.ApplicationError( urlfetch_service_pb.URLFetchServiceError.FETCH_ERROR, error_msg) 
</pre>

You may wish to make the same change for Https as well. It would not be too hard to fix it the right way by having it check for the http_proxy environment variable, but I haven’t done that.

This entry was posted in Python. Bookmark the permalink.

One Response to Forcing a HTTP Proxy on Local Google App Engine Development Server

  1. Anonymous says:

    Brilliant, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>