Hot!Python for Fortigate API

Author
xxddpac
New Member
  • Total Posts : 7
  • Scores: 0
  • Reward points: 0
  • Joined: 2018/11/28 04:38:57
  • Status: offline
2018/11/28 04:48:35 (permalink)
0

Python for Fortigate API

Hi,Guys
I have a problem with FGT60E API token.
The python code is as follows:
========================================================================
========================================================================
import json,urllib3,requests
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
url = "https://X.X.X.X:4433"
fgt_url = "https://X.X.X.X:4433/logincheck"
# fgt_coo = requests.post(fgt_url,data={"username":"aaaaa","secretkey":"aaaaaaa",
# "ajax":1},verify = False)
# headers = {"Cookie":"APSCOOKIE_2405464622=%s;ccsrftoken=%s"%(fgt_coo.cookies.get("APSCOOKIE_2405464622"),
# fgt_coo.cookies.get("ccsrftoken"))}
myToken = "9qcGftQshfk9Hhqp9Gzxxx7rd14djg"
apikey = {'Authorization': 'python {}'.format(myToken)}
cmdb = url + "/api/v2/cmdb"
res = requests.get(url = cmdb,headers = apikey,verify = False)
print res.content
# result = json.loads(res.content)
# print result["version"]
# print result["serial"]
================================================================================
================================================================================
The result :
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>401 Authorization Required</TITLE>
</HEAD><BODY>
<H1>Authorization Required</H1>
This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.<P>
<P>Additionally, a 401 Authorization Required
error was encountered while trying to use an ErrorDocument to handle the request.
</BODY></HTML>
 
The Firewall already created API User "python" and generate key.
I used cookie its ok, but api key failed.
Can anyone help me ?
#1

5 Replies Related Threads

    xxddpac
    New Member
    • Total Posts : 7
    • Scores: 0
    • Reward points: 0
    • Joined: 2018/11/28 04:38:57
    • Status: offline
    Re: Python for Fortigate API 2018/11/28 18:17:03 (permalink)
    0
    Any ideas ?
    #2
    pcraponi
    Gold Member
    • Total Posts : 451
    • Scores: 26
    • Reward points: 0
    • Joined: 2006/07/28 11:43:39
    • Location: Brazil
    • Status: offline
    Re: Python for Fortigate API 2018/11/29 03:51:49 (permalink)
    0
    Take a look here in some examples: https://github.com/barbosm/gatepy
     
    maybe can help you..
    #3
    xxddpac
    New Member
    • Total Posts : 7
    • Scores: 0
    • Reward points: 0
    • Joined: 2018/11/28 04:38:57
    • Status: offline
    Re: Python for Fortigate API 2018/11/30 01:35:42 (permalink)
    0
    p****oni
    Take a look here in some examples: https://github.com/barbosm/gatepy
     
    maybe can help you..


    Many thanks !!
    #4
    jamerst26
    New Member
    • Total Posts : 2
    • Scores: 0
    • Reward points: 0
    • Joined: 2020/02/05 00:13:32
    • Status: offline
    Re: Python for Fortigate API 2020/02/05 00:24:49 (permalink)
    0
    You have Reference document
    #5
    rpereira
    New Member
    • Total Posts : 1
    • Scores: 0
    • Reward points: 0
    • Joined: 2020/07/30 08:01:13
    • Status: offline
    Re: Python for Fortigate API 2020/07/30 08:03:12 (permalink)
    0
    I had similar problem (error 401).
    In my case, the Token had an extra '\n'.
    Confirm the url sent with res.url.
    #6
    Jump to:
    © 2020 APG vNext Commercial Version 5.5