python proxy to embed a google apps script service

2019-03-06 09:45发布

问题:

There's "X-Frame-Options: SAMEORIGIN" header preventing the Apps Script from rendering in a page not from sites.google.com (or docs.google.com)

How can I create a python proxy to work from an IFrame. I suspect the proxy needs to replace the SAMEORIGIN tag and work with ajax style POST commands. This is new ground for me, never needed to setup a proxy before.

Example Google Apps Script page: https://docs.google.com/macros/exec?service=AKfycbyrbgVS39Hf-RHYVPbnCKzf_uVaD0sGeFSKEqyRIw

This proxy solutions looks close: How do I get my simple twisted proxy to work?

I found instructions for setting up a proxy on App Engine, but this fails with ajax style POST commands: http://www.labnol.org/internet/setup-proxy-server/12890/

This is a known Google Apps Script issue #546 and #522. About 1 year old with about 100 people looking for a solution.

回答1:

The bs2grproxy works with a few small changes. I posted the solution here: http://code.google.com/p/google-apps-script-issues/issues/detail?id=546#c104

The changes:

In file bs2grproxy.py below line 48, "raise Exception('Unsupported ..." insert:

        scm = 'https'

below line 134, "raise Exception('Requested ..." insert:

            if fetched:
                if resp.headers.get('Content-Type', '').find('html') >= 0:
                    resp.content = resp.content + '<style type="text/css"> .warning-panel {display: none;} </style>'
                    resp.headers['x-frame-options'] = 'IGNORE'
                    logging.info("warning-panel hidden and x-frame-options reset")

You may also need to change the proxy time out in bs2grproxy.py, like this:

resp = urlfetch.fetch(new_path, self.request.body, method, newHeaders, False, False, 30)

Eddy.