PCPP 32 10x PCPP Certified Professional Python Programmer 1 · Free Practice Question Easy
Question 25
Suppose you have the following request:
- import requests
- reply = requests.get('http://python.org:80')
How can you access the headers and content-type information?
-
A
reply.headers['Connection'] -
B
reply.headers['Server'] -
C
reply.headers['Content-Type'] -
D
reply.headers['Text']
Reveal correct answer
Correct answer: C
A.
This option accesses the Connection header, which typically indicates the type of connection the server wants to establish (e.g., keep-alive or close). While it’s a valid header, it does not provide the Content-Type information.
B.
This option accesses the Server header, which provides information about the server software handling the request (e.g., Apache, nginx). This header is not related to Content-Type.
C.
This is the correct way to access the Content-Type information from the headers. The Content-Type header indicates the media type of the resource (e.g., text/html, application/json), which tells the client how to interpret the data.
D.
There is no standard Text header in HTTP. This option would likely raise a KeyError if accessed because it does not exist in the typical set of HTTP headers.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
