CiscoDevNet / devnet-express-code-samples

Archived: This repository holds code samples for DevNet Express DNA Track
47 stars 102 forks source link

Verify Status Code on apic-em module #19

Closed robertcsapo closed 7 years ago

robertcsapo commented 7 years ago

LM4502 doesn't have response.raise_for_status() to indicate if there's issues with the API call

code

response = requests.post(url, data=json.dumps(payload), headers=headers, verify=False)
response.raise_for_status()
response = response.json()

output

Traceback (most recent call last):
  File "apic_em_code_1.py", line 86, in <module>
    auth_token = get_token(apic_em_ip)
  File "apic_em_code_1.py", line 28, in get_token
    response.raise_for_status()
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 909, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://sandboxapic.cisco.com/api/v1/ticket
austinMarcos commented 7 years ago

Armen-

I'm not sure if you were involved with the original creation of this script, but can you look into why that response.raise_for_status() function is missing from:

https://github.com/CiscoDevNet/devnet-express-code-samples/blob/master/LM-4502/03-python/apic_em_code_1.py

robertcsapo commented 7 years ago

If you want, I can make PR for these 10 requests

grep -i "response = requests" 03-python/* | wc -l
6
grep -i "response = requests" 04-mission/* | wc -l
4
austinMarcos commented 7 years ago

Yes, Robert. Please make the pull request. Thanks!

robertcsapo commented 7 years ago

review the code and let me know if it's ok