0

I have a python code where I am making a https request.

        import urllib3
        https = urllib3.PoolManager(cert_reqs=ssl.CERT_NONE)

Here is how I am making a call to an api

        myResponse = https.request(method="GET", url=f"{myEndpoint}?acctId={accountID}&acctType={accountType}", headers=headers)
        response = json.loads(myResponse.data.decode("UTF-8"))

I know that response does not contain response["Records"]

I want to have few more lines of code but will need to run those lines if response contains response["Records"]

The code below always runs because response["Records"] is not contained in the response

        if((response["Records"] != None) and (len(response["Records"]) != 0)): 
             pass 

How can I write the python code to check response and only run my other lines of code if response["Records"] exit in response?

Baba
  • 2,059
  • 8
  • 48
  • 81
  • `if response.get("Records") is not None:` – JonSG Aug 18 '23 at 18:23
  • Does this answer your question? [Why dict.get(key) instead of dict\[key\]?](https://stackoverflow.com/questions/11041405/why-dict-getkey-instead-of-dictkey) – JonSG Aug 18 '23 at 18:26

0 Answers0