問題
Catalyst Center(旧DNA Center)のIntent APIで、Baltimoreに所在するデバイスの一覧を取得する。次の①〜④へ入る組合せはどれか。
import requests
url = f"{BASE_URL}/dna/intent/api①?②"
headers = {
'X-auth-token': 'eyJhbGc ... yJbN8',
'Content-Type': 'application/json',
}
response = requests.request('GET', url, headers=headers)
if response.status_code == ③:
print(response.text.encode('utf8'))
elif response.status_code == ④:
print("ERROR: Request syntax incorrect")
候補:/v1/devices、location=BALTIMORE、200、400、geolocation=BALTIMORE、/v1/network-device。
- A
① /v1/network-device、② location=BALTIMORE、③ 200、④ 400
- B
① /v1/devices、② location=BALTIMORE、③ 200、④ 400
- C
① /v1/network-device、② geolocation=BALTIMORE、③ 200、④ 400
- D
① /v1/network-device、② location=BALTIMORE、③ 400、④ 200
正解:A
理由
デバイス一覧のnetwork-deviceにlocationのクエリを付ける。HTTP 200は取得成功、400は要求の不正を表す。Pythonの条件分岐はelifと記述する。
選択肢ごとの説明
- A.
① /v1/network-device、② location=BALTIMORE、③ 200、④ 400
network-deviceの一覧をlocationで絞り、200を成功、400を要求構文などのエラーとして処理する。
- B.
① /v1/devices、② location=BALTIMORE、③ 200、④ 400
このIntent APIのデバイス一覧はnetwork-deviceである。
- C.
① /v1/network-device、② geolocation=BALTIMORE、③ 200、④ 400
このAPIのフィルター名はlocationである。
- D.
① /v1/network-device、② location=BALTIMORE、③ 400、④ 200
成功と要求エラーの応答コードが逆になっている。