• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 30 pages
Exam (elaborations)

Wgu D522 Python For It Automation (Sko1) Study Tips Exam Questions And Correct Answers With Rationales| Instant Download

Document preview thumbnail
Preview 3 out of 30 pages

Practice questions with answers and rationales covering Python for IT automation: subprocess error handling, requests rate limiting and backoff, and symlinks, secrets management, paramiko SSH, file iteration for large logs, ThreadPoolExecutor limits, , and logging handlers. Each question explains why the correct answer works, so you can review the reasoning and prepare for the D522 exam.

Content preview

, Question 1
A script uses `subprocess.run(['ping', '-c', '1', host], capture_output=True,
text=True, check=True)` inside a loop over 10,000 hosts. It fails on the first
unreachable host. Which change best preserves error handling while avoiding a
crash?
A. Replace check=True with check=False and inspect returncode for each
host.
B. Set check=True but wrap the call in a try/except
subprocess.CalledProcessError.
C. Use subprocess.Popen with shell=True and ignore errors.
D. Remove capture_output=True to reduce memory usage.
Correct Answer: B - Set check=True but wrap the call in a
try/except subprocess.CalledProcessError.


RATIONALE
Wrapping in try/except subprocess.CalledProcessError allows the loop
to continue while still detecting failures via the exception. Option A
also avoids crashing but loses the explicit exception handling and
requires manual returncode checks, which is less idiomatic. Option C
introduces shell injection risks and ignores errors. Option D does not
address the error.

Question 2
When automating REST API calls with the `requests` library, which approach
best handles rate limiting (HTTP 429) while maintaining resilience and
avoiding infinite loops?
A. Retry immediately in a while loop until success.
B. Use a fixed 1-second delay between retries and ignore the Retry-After
header.
C. Implement exponential backoff with a maximum retry limit, respecting
the Retry-After header if present.



Page 2

, D. Catch the exception and log it, then continue without retrying.


Correct Answer: C - Implement exponential backoff with a
maximum retry limit, respecting the Retry-After header if
present.


RATIONALE
Exponential backoff with a retry limit prevents overwhelming the
server and avoids infinite loops, while respecting Retry-After aligns
with server guidance. Option A can cause hammering and infinite
loops. Option B ignores server-provided timing and may still hit rate
limits. Option D abandons the request entirely.

Question 3
A Python script uses `os.walk()` to delete all `.tmp` files in a directory tree.
Which modification ensures that symbolic links to directories are not followed,
preventing unintended deletions outside the tree?
A. Set `followlinks=False` in `os.walk()` (default).
B. Use `os.path.islink()` to check each file before deletion.
C. Set `followlinks=True` to ensure all links are processed.
D. Replace `os.walk()` with `glob.glob('**/*.tmp', recursive=True)`.
Correct Answer: A - Set `followlinks=False` in `os.walk()`
(default).


RATIONALE
By default, `os.walk()` does not follow symbolic links to directories
(followlinks=False), which prevents traversal outside the intended
tree. Option B checks files, not directory links, and may miss
symlinked directories. Option C explicitly enables following links,
increasing risk. Option D with `glob` may also follow symlinks
depending on the Python version and flags.




Page 3

Document information

Uploaded on
October 1, 2026
Number of pages
30
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$30.00

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
CaseHero
3.8
(4)
Sold
20
Followers
0
Items
6236
Last sold
6 days ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions