- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Any ideas ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Take a look here in some examples: https://github.com/barbosm/gatepy
maybe can help you..
Regards, Paulo Raponi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
p****oni wrote:Many thanks !!Take a look here in some examples: https://github.com/barbosm/gatepy
maybe can help you..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have Reference document
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I had similar problem (error 401).
In my case, the Token had an extra '\n'.
Confirm the url sent with res.url.
