nerdexam
CiscoCisco

200-901 · Question #509

200-901 Question #509: Real Exam Question with Answer & Explanation

The correct answer is A: requests.get(url, auth=('admin', 'devnet123')). The Python requests library accepts a plain tuple of (username, password) as the auth argument to automatically encode and send HTTP Basic Auth credentials.

Understanding and Using APIs

Question

Refer to the exhibit. A developer creates a Python script to query a REST API by using an HTTP GET request. The remote server will authorize the request only if it includes HTTP Basic Auth parameters. The username is admin and the password is devnet123. Which line of code needs to be placed on the snippet where the code is missing? A. B. C. D.

Options

  • Arequests.get(url, auth=('admin', 'devnet123'))
  • Brequests.get(url, auth=HTTPDigestAuth('admin', 'devnet123'))
  • Crequests.get(url, auth=HTTPBasicAuth('admin': 'devnet123'))
  • Drequests.get(url, auth='admin', 'devnet123')

Explanation

The Python requests library accepts a plain tuple of (username, password) as the auth argument to automatically encode and send HTTP Basic Auth credentials.

Common mistakes.

  • B. HTTPDigestAuth implements the HTTP Digest authentication scheme, which uses a challenge-response mechanism - it does not satisfy a Basic Auth requirement.
  • C. HTTPBasicAuth('admin': 'devnet123') uses a colon inside the parentheses, which is Python dictionary key syntax and causes a SyntaxError; the correct delimiter between positional arguments is a comma.
  • D. The auth parameter accepts a single value (a tuple or auth object); passing 'admin' and 'devnet123' as two separate positional arguments to requests.get() is a SyntaxError and will not execute.

Concept tested. Python requests library HTTP Basic Auth usage

Reference. https://requests.readthedocs.io/en/latest/user/authentication/#basic-authentication

Topics

#Python#requests library#REST API#HTTP Basic Auth

Community Discussion

No community discussion yet for this question.

Full 200-901 PracticeBrowse All 200-901 Questions