I have to store some json datas into db via fastapi. i have more than hundred datas and I cant enter it manually so i decided to create one python script and then after i send those datas via script. but while execution i'm getting some errors. i'm new to python please help me out
import requests
import urllib3
import json
import ast
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
API_ENDPOINT = "https://100.70.180.88:33011/ntspapi/mariadb/db_insert"
API_KEY = "VARE56EF4W68V4v4rw68v13s5D1FV86WRE4Va1365v4"
input ={"ntsp_input": {
"table": "NTSP_NF_DETAILS",
"input": {
"server_name": "mss077_1",
"connection": "",
"type": "MGCF",
"auth_type": "",
"ssh_ip": "172.17.15.10",
"ssh_username": "",
"ssh_password": "",
"ssh_key": "",
"ssh_port": "",
"rest_ip": "",
"rest_port": "",
"rest_username": "",
"rest_password": "",
"rest_token_path": "",
"remote_folder": "",
"sftp_username": "",
"sftp_password": "",
"sftp_port": "",
"sftp_key": "",
"server_support": "",
"common_server_connection": "",
"groupname": "",
"unique_identifier": "",
"fqdn": "",
"interface": "[\"any\"]",
"duration": "",
"filter": "",
"network_analyzer": "",
"capture_timeout": 0,
"task_timeout": 0
},
"condition": "None"
}
}
"""changing python dict into json"""
input_data = json.dumps(input)
input_json = ast.literal_eval(input_data)
data = {'api_dev_key': API_KEY,
'api_option':'paste',
'api_paste_code': input_json,
'api_paste_format':'json'
}
response = requests.post(url=API_ENDPOINT, data = data, verify=False)
print(response.text)
print(response.status_code)
this is my python code.I'm sending JSON input to FASTAPI via python script. but while executing I'm getting some response I mentioned below
- {"detail":[{"loc":["body",0],"msg":"Expecting value: line 1 column 1 (char 0)","type":"value_error.jsondecode","ctx":{"msg":"Expecting value","doc":"api_dev_key=VARE56EF4W68V4v4rw68v13s5D1FV86WRE4Va1365v4&api_option=paste&api_paste_code=ntsp_input&api_paste_format=json","pos":0,"lineno":1,"colno":1}}]}