cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
673
Views
0
Helpful
2
Comments
isaac_ferreira
Level 1
Level 1

Hello Guys,

 

I'm trying to create a simple script to create new objects on FMC via API, but I'm facing issues(Python 3.8).

 

Script(that pretty simple, I'm not programmer, but I'm trying):

 

import base64
import sys
import requests
import re
import json

#FMC VALUES
FMC = {
"ip": "192.168.200.100",
"port": "443",
"user": "adminapi",
"password": "C1sco12345!"
}

headers = \
{
"X-auth-access-token": "ecf8c94f-3a35-4bd7-9a4a-5e125b8d607e"
}
#URL para acesso#
api_url = "https://{}/api/fmc_config/v1/domain/e276abec-e0f2-11e3-8169-6d9ed49b625f/object/hosts"
url = api_url.format(FMC["ip"])


#Data to be inserted

post_data = {
"name": "Python5",
"value": "10.10.10.10",
"type": "Host",
"description": "First Python Object"
}


#Request#
response = requests.post(url, data=json.dumps(post_data), verify=False, headers=headers)
status_code = response.status_code
resp_body = response.text
resp_header = response.headers

print(status_code)
print(resp_body)
print(resp_header)

outputs:
500
{"error":{"category":"OTHER","messages":[{}],"severity":"ERROR"}}
{'Date': 'Fri, 25 Sep 2020 03:12:36 GMT', 'Server': 'Apache', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', 'Cache-Control': 'no-store', 'Accept-Ranges': 'bytes', 'X-Frame-Options': 'SAMEORIGIN', 'X-UA-Compatible': 'IE=edge', 'X-Permitted-Cross-Domain-Policies': 'none', 'X-XSS-Protection': '1; mode=block', 'Referrer-Policy': 'same-origin', 'X-Content-Type-Options': 'nosniff', 'Connection': 'close', 'Transfer-Encoding': 'chunked', 'Content-Type': 'application/json'}

I've received this error on FMC GUI:
Internal Server Error (500) - The server encountered an unexpected condition which prevented it from fulfilling the request

Debugs using pigtail
USMS: 09-25 02:56:30
USMS: 09-25 02:56:30 [INFO],(DefenseCenterServiceImpl.java:1394)
USMS: 09-25 02:56:30 com.cisco.nm.vms.api.dc.DefenseCenterServiceImpl, ajp-nio-127.0.0.1-9009-exec-4
USMS: 09-25 02:56:30 ** REST Request [ CSM ]
USMS: 09-25 02:56:30 ** ID : eaf4e0ff-ad70-4a9a-85a2-1824ed7782f8
USMS: 09-25 02:56:30 ** URL: POST /audit
USMS: 09-25 02:56:30 {
USMS: 09-25 02:56:30 "version": "6.5.0",
USMS: 09-25 02:56:30 "requestId": "eaf4e0ff-ad70-4a9a-85a2-1824ed7782f8",
USMS: 09-25 02:56:30 "data": {
USMS: 09-25 02:56:30 "userName": "adminapi",
USMS: 09-25 02:56:30 "subsystem": "API",
USMS: 09-25 02:56:30 "message": "POST https://192.168.200.100/api/fmc_config/v1/domain/e276abec-e0f2-11e3-8169-6d9ed49b625f/object/hosts Internal Server Error (500) - The server encountered an unexpected condition which prevented it from fulfilling the request",
USMS: 09-25 02:56:30 "sourceIP": "192.168.0.4",
USMS: 09-25 02:56:30 "domainUuid": "e276abec-e0f2-11e3-8169-6d9ed49b625f",
USMS: 09-25 02:56:30 "time": "1601002590701"
USMS: 09-25 02:56:30 },
USMS: 09-25 02:56:30 "deleteList": []
USMS: 09-25 02:56:30 }
USMS: 09-25 02:56:30
TCAT: 09-25 02:56:30 INFO: 192.168.0.4 - 127.0.0.1 443 POST /api/fmc_config/v1/domain/e276abec-e0f2-11e3-8169-6d9ed49b625f/object/hosts - 500 - 121 209 https://192.168.200.100 python-requests/2.24.0 -
USMS: 09-25 02:56:30
USMS: 09-25 02:56:30 [INFO],(DefenseCenterServiceImpl.java:1414)
USMS: 09-25 02:56:30 com.cisco.nm.vms.api.dc.DefenseCenterServiceImpl, ajp-nio-127.0.0.1-9009-exec-4
USMS: 09-25 02:56:30 ** REST Response [ DC ]
USMS: 09-25 02:56:30 ** ID : eaf4e0ff-ad70-4a9a-85a2-1824ed7782f8
USMS: 09-25 02:56:30 ** URL: POST /audit
USMS: 09-25 02:56:30 {
USMS: 09-25 02:56:30 "version": "6.0.1",
USMS: 09-25 02:56:30 "id": "1649",
USMS: 09-25 02:56:30 "requestID": "eaf4e0ff-ad70-4a9a-85a2-1824ed7782f8",
USMS: 09-25 02:56:30 "message": "Success",
USMS: 09-25 02:56:30 "code": 200
USMS: 09-25 02:56:30 }
USMS: 09-25 02:56:30

i really appreciate your help

 

 

 

2 Comments
shehreyarkhan
Level 1
Level 1

Hi,

I am facing the same issue, did find the solution to correct it ?

Regards

Volodymyr2222
Level 1
Level 1

 Faced the same issue, resolved for me after adding content-type to headers

headers = {
    "X-auth-access-token": "ecf8c94f-3a35-4bd7-9a4a-5e125b8d607e",
    "Content-Type": "application/json"
}

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: