Support Forum
The Forums are a place to find answers on a range of Fortinet products from peers and product experts.
NeTunnel
New Contributor

Forigate 6.0.10 API python return code 401

Hello,

I Using the next python code:

import  requests
import json
api_url='https://x.x.x.x/api/v2/monitor/system/config/backup?scope=global&access_token=MYTOKEN'
requests.packages.urllib3.disable_warnings()
data=requests.get(api_url,verify=False)
print(data.status_code)
print(data)
'''Get license status'''  

when i run this code i get error code 401

for the API profile i allowed read/write.

 

Please someone can share with me python code that work with fortigate API ?
and why my code is not working...

 


 

5 REPLIES 5
bpozdena_FTNT

The 401 response code is most likely caused by invalid API key (access_token). 

 

HTH,
Boris
NeTunnel

I run the following debug commands:

 (global) # diagnose debug resetA
 (global) # diagnose debug enable
 (global) # diagnose debug application httpsd -1
Debug messages will be on for 30 minutes.

I get errror :  Peer not trusted:

bpozdena_FTNT

Are you connecting to the API from a trusted host? 

Reference: https://docs.fortinet.com/document/fortigate/6.0.0/cookbook/222079/using-a-trusted-host-optional 

HTH,
Boris
NeTunnel
New Contributor

Yes for the check i configure 0.0.0.0
Also if i copy the api request and put it on my browser this work.

If i run the api request from python i get error..

Jackstorm
New Contributor II

You can’t set 0.0.0.0, when you use api key, try to set specific host. 


Lucas
Lucas
Announcements

Select Forum Responses to become Knowledge Articles!

Select the “Nominate to Knowledge Base” button to recommend a forum post to become a knowledge article.

Labels
Top Kudoed Authors