jsonapipython-3.5google-python-api

How to add drop down list parameters into restapi url using python Post request


Getting below error-

raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

In below python code the parameters have 2 dropdown list i.e. dataFormat and metrics ,others are normal input parmaeters. I am getting above error while executing the below code.

Note- Input parameters are in JSON format

Please help to solve.

import sys

sys.path.append("C:/pythonmodules")

import requests

import json

from requests.auth import HTTPBasicAuth

import urllib.parse

from urllib.parse import urlencode

from urllib.request import Request, urlopen

headers={'content-type':'application/json'}

par = {'startDate': '1548061800000', 'endDate': '1548061800000', 'symmetrixId': '000', 'storageGroupId': 'TOD', 'dataFormat':'Average', 'metrics':'HostIOs' }

SGUrl = "xxxxxxxxxxx"

response1 = requests.post(SGUrl, auth=HTTPBasicAuth('pe', 'pe'), verify=False, data =json.dumps(par),  headers=headers)

print (par)

perfSG = response1.json()

print (perfSG)`

Solution

  • I got the answer.my input parameters I have given wrong. In par the date should be in numbers not a string.