python proxy to embed a google apps script service in an iframe

别来无恙 提交于 2019-12-02 20:20:55

问题


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.



来源:https://stackoverflow.com/questions/10510425/python-proxy-to-embed-a-google-apps-script-service-in-an-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!