APIs With Python

Last Updated :
Discuss
Comments

Question 1

What does the requests.get() function do in Python?

  • A

    Updates data on the server

  • B

    Retrieves data from a URL

  • C

    Deletes data on the server

  • D

    Uploads files

Question 2

What will this code return if the request is successful?

Python
import requests
response = requests.get("https://api.github.com")
print(response.status_code)


  • A

    404

  • B

    500

  • C

    200

  • D

    None

Question 3

Which of these methods is used to send data to a server in a request body?

  • A

    GET

  • B

    POST

  • C

    DELETE

  • D

    HEAD

Question 4

What does the response.json() method return in Python’s requests module?

  • A

    The raw string of the response

  • B

    A dictionary from the JSON response

  • C

    An XML document

  • D

    List of headers

Question 5

What will happen if you access a URL with an invalid SSL certificate using requests without disabling verification?

  • A

    It returns status code 200

  • B

    It raises an SSLError

  • C

    It auto-validates the SSL

  • D

    It retries the request

Question 6

How can you disable SSL verification in Python requests?

  • A

    verify=False in get() method

  • B

    Remove headers

  • C

    Use http instead of https

  • D

    Use json=False

Question 7

Which requests method can be used to modify part of a resource on a server?

  • A

    PATCH

  • B

    PUT

  • C

    DELETE

  • D

    GET

Question 8

What is the purpose of a Session object in the requests module?

  • A

    To upload files

  • B

    To manage browser sessions

  • C

    To persist cookies and connection pooling

  • D

    To track request history

Question 9

In the following code, what does params do?

Python
params = {
    "country": "us",
    "apiKey": API_KEY,
}
response = requests.get(url, params=params)


  • A

    It adds authentication headers

  • B

    It sets up a timeout

  • C

    It adds query parameters to the URL

  • D

    It disables SSL

Question 10

What does this line do in a Python script using the NewsAPI?

Python
articles = response.json().get('articles', [])


  • A

    Loads XML content

  • B

    Returns all articles in JSON data

  • C

    Returns first image only

  • D

    Returns 404 if articles not found

There are 12 questions to complete.

Take a part in the ongoing discussion