redirection not working in python for locally hosted form snippet for cgiserver
<p>I am trying to use the following created html page to access information from a cgiserver using python. I am implementing auto redirection using javascript at bottom</p>

<pre><code>&lt;form action="http://pi-web.cisco.com/pims-home/fcgi-bin/BugReport/DDTS.cgi?Function=DDTS"&gt;
&lt;input type="hidden" name="Function" value="DDTS"&gt;
By Production Build: &lt;td valign=top&gt;
&lt;table border=0 cellpadding=0 cellspacing=0&gt;
&lt;tr&gt;
&lt;td valign=top&gt;
&amp;nbsp;From:&amp;nbsp;&lt;/td&gt;
&lt;td valign=top&gt;
&lt;select name=from_prod_build&gt;
&lt;option value="6_2_1_14I_DT_IMAGE" selected&gt;6_2_1_14I_DT_IMAGE&lt;/option&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;td valign=top&gt;
&amp;nbsp;To:&amp;nbsp;&lt;/td&gt;
&lt;td valign=top&gt;
&lt;select name=to_prod_build&gt;
&lt;option value="6_2_1_16I_DT_IMAGE" selected&gt;6_2_1_16I_DT_IMAGE&lt;/option&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;input type=checkbox name=explicit_only value=1&gt;
Explicit Commits Only&lt;/td&gt;
&lt;td valign=bottom&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;button type="submit" id="submit"name='by prod_bld'&gt;
&lt;/button&gt;
&lt;script type="text/javascript"&gt;
document.getElementById("submit").click();&lt;/script&gt;
&lt;/form&gt;
&lt;/td&gt;
</code></pre>

<p>However, i see in a web browser the page redirects and show the information but in python I can only fetch the created page and not redirected page. Below is the python script</p>

<pre><code>from lxml import html
import requests
page=requests.get('http://localhost/requestDDTS.html',allow_redirects=True)
print(page.url)
tree = html.parse(page.text)
</code></pre>

<p>How can i fix this?</p>

<p>You can only get first page because there is no redirect.</p>

<p>In HTML page you have form, that is automatically submitted to <code>http://pi-web.cisco.com/pims-home/fcgi-bin/BugReport/DDTS.cgi?Function=DDTS</code>. First site returns with code 200 and not 301/302. Requests library doesn't parse javascript inside html document, it just fetches text content.</p>

<p>Put this in python script:</p>

<pre><code>payload = {
    'Function': 'DDTS',
    'by prod_bld': '',  #this looks like typo, space instead of _ ?
    'from_prod_build' : '6_2_1_14I_DT_IMAGE',
    'to_prod_build' : '6_2_1_16I_DT_IMAGE'
}

page = requests.get('http://pi-web.cisco.com/pims-home/fcgi-bin/BugReport/DDTS.cgi', params=payload)
</code></pre>

<p>This should return the same page as the one you see after form submit in browser.</p>

javascript python cgi python-requests