Hi, I am writing a web2py application, that pulls HTML output from another web app (specifically, Splunk web, if anyone cares).
Here is the function that I have arrived at the moment: import requests as http def splunk(): kwargs = dict(verify=False) svc = request.get_vars.get('service') sess = session.proxy_session sessid = sess.cookies.get('session_id_8001') logger.debug('midash/proxy/splunk: Session = %s'%(format(sess))) if sess is None: sess = http.Session() logger.debug('midash/proxy/splunk: Initial contact') resp = sess.get('https://localhost:8001/', **kwargs) resp = splunk_auth(sess, **kwargs) url = 'https://localhost:8001'+(request.vars._url or '') resp = sess.get(url, **kwargs) if (sessid != resp.cookies.get('session_id_8001')): resp = splunk_auth(sess, app=url, **kwargs) logger.debug('midash/proxy/splunk: url = "%s" %s)'%(url, format(resp))) for hkey,hval in resp.headers.iteritems(): logger.debug('midash/proxy/splunk: header[%s] = %s'%(hkey, hval)) session.proxy_session = sess for hkey in [ 'conten-type' ]: hval = resp.headers.get(hkey) if hval: response.headers[hkey] = hval return response.stream(resp.raw) def splunk_auth(sess, app='%2Fen-US%2F', **kwargs): cval = sess.cookies.get('cval') uagent = request.env.user_agent if uagent: sess.headers['User-Agent'] = uagent logger.debug('midash/proxy/splunk_auth: cval = %s, app=%s'%(cval, app)) return sess.post( 'https://localhost:8001/en-US/account/login?return_to=%s'%(app), data = dict(username='admin', password='changeme',cval = cval), **kwargs) For debugging purpose, I made a small wrapper class to wrap "resp.raw" which is a urllib3.HTTPResponse object. In debug logging, I can see that I get the contents I expected from https://localhost:8001/. However, in the browser, the call going to the above splunk function would get a status 200 with 0-byte content (debug logging shows header[content-length] = 14372.) Is return response.stream() the right way for this? Thanks! -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.