Skip to content
This repository was archived by the owner on Aug 21, 2018. It is now read-only.

Verify Status Code on apic-em module #19

Closed
robertcsapo opened this issue May 4, 2017 · 4 comments
Closed

Verify Status Code on apic-em module #19

robertcsapo opened this issue May 4, 2017 · 4 comments

Comments

@robertcsapo
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

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

@robertcsapo
Copy link
Contributor Author

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

@austinMarcos austinMarcos added this to the Triage/Scrub review milestone May 5, 2017
@austinMarcos austinMarcos self-assigned this May 5, 2017
austinMarcos added a commit that referenced this issue May 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants