title: Redirected to login after API call to firewall
body: <p>For a project I have to make an api call to a fortigate firewall ,I am able to bypass the SSL certificate but after that I <strong>get redirected to the login page</strong>, even though i have used an authoriziation key (username+password base64-encoded).</p>
  
  <p>my code:</p>
  
  <pre><code>import urllib2,ssl
  
  u='username'
  p='password'
  url='https://fortigate-url/api/v2/cmdb/firewall/policy/?vdom=root'
  
  
  def encodeUserData(user, password):
  return "Basic " + (user + ":" + password).encode("base64").rstrip()
  
  
  req = urllib2.Request(url)
  req.add_header('Accept', 'application/json')
  req.add_header("Content-type", "application/x-www-form-urlencoded")
  req.add_header('Authorization', encodeUserData(u, p))
  
  ctx = ssl.create_default_context()
  ctx.check_hostname = False
  ctx.verify_mode = ssl.CERT_NONE
  
  res = urllib2.urlopen(req,context=ctx)
  print res.read()
  </code></pre>
  
  <p>this is the same output I get if i try the same using CURL.</p>
  
  <pre><code>GET /login?redir=%2fapi%2fv2%2fcmdb%2fpolicy%2f%3fvdom=root%2f HTTP/1.1
  
  Host: 198.51.150.55
  User-Agent: curl/7.53.1
  Authorization: Rftfa4fYm=
  Accept:application/json
  
  HTTP/1.1 200 OK
  Date: Tue, 21 Mar 2017 11:53:06 GMT
  Set-Cookie: APSCOOKIE_2199254599="0%260"; path=/; expires=Mon, 03-Apr-1967 11:53:06 GMT
  Set-Cookie: log_filters="0%260"; path=/log/; expires=Mon, 03-Apr-1967 11:53:06 GMT
  Set-Cookie: log_type="0%260"; path=/log/; expires=Mon, 03-Apr-1967 11:53:06 GMT
  Set-Cookie: just_logged_in="0%260"; path=/system/status/; expires=Mon, 03-Apr-1967 11:53:06 GMT
  Set-Cookie: opmode="0%260"; path=/; expires=Mon, 03-Apr-1967 11:53:06 GMT
  Set-Cookie: csrftoken="0%260"; path=/; expires=Mon, 03-Apr-1967 11:53:06 GMT
  Set-Cookie: ccsrftoken="0%260"; path=/; expires=Mon, 03-Apr-1967 11:53:06 GMT
  Set-Cookie: last_l3_menu="0%260"; path=/p/system/navbar/; expires=Mon, 03-Apr-1967 11:53:06 GMT
  Set-Cookie: fsck="0%260"; path=/; expires=Mon, 03-Apr-1967 11:53:06 GMT
  Transfer-Encoding: chunked
  Content-Type: text/html; charset=utf-8
  X-Frame-Options: SAMEORIGIN
  X-UA-Compatible: IE=Edge
  
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html style="height:100%"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;meta http-equiv="pragma" content="no-cache"&gt;
  &lt;link href="/25689/style.css" rel="stylesheet" type="text/css"&gt;
  &lt;link href="/25689/css/jquery.ui.css" rel="stylesheet" type="text/css"&gt;
  &lt;script type='text/javascript' src='/25689/lang/en.js'&gt;&lt;/script&gt;
  &lt;script language="JavaScript"&gt;
  if (top.location != window.location) top.location.reload();    
  if (window.opener) {window.opener.top.location.reload(); self.close();}
  var redir = '\/api\/v2\/cmdb\/firewall\/policy\/?vdom=root\/';
  &lt;/script&gt;
  &lt;link href="/25689/css/login.css" rel="stylesheet" type="text/css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;table id="container"&gt;
  &lt;tr&gt;&lt;td&gt;
  &lt;noscript id="js_msg_txt"&gt;Warning: this page requires Javascript. To         correctly view, please enable it in your browser.&lt;/noscript&gt;
  &lt;form id="login_panel" action="" onsubmit="return false;" method="get"     name="login" autocomplete="off"&gt;
  &lt;div name="err_msg_txt" id="err_msg_txt"&gt;&amp;nbsp;&lt;/div&gt;
  &lt;label for="username"&gt;Name&lt;/label&gt;
  &lt;input type="text" name="username" id="username" value="" maxlength="35"     autocorrect="off" autocapitalize="off" &gt;
  &lt;label for="secretkey"&gt;Password&lt;/label&gt;
  &lt;input type=password autocomplete="off" name="secretkey" id="secretkey"&gt;
  ...
  * Connection #0 to 'fortigate url' left intact
  </code></pre>
  
  <p>Is it possible to bypass the login using the same script ?</p>