Complete the code to send a DELETE request to remove a user by ID.
response = requests.[1]('https://api.example.com/users/123')
The DELETE method is used to remove a resource from the server.
Complete the code to check if the DELETE request was successful by verifying the status code.
if response.status_code == [1]: print('Deleted successfully')
Status code 204 means the server successfully processed the request and is not returning any content.
Fix the error in the code to correctly send a DELETE request with headers.
headers = {'Authorization': 'Bearer token123'}
response = requests.[1]('https://api.example.com/items/45', headers=headers)To delete a resource with headers, use the DELETE method with the headers parameter.
Fill both blanks to create a function that deletes a resource by ID and returns True if successful.
def delete_resource(resource_id): response = requests.[1](f'https://api.example.com/resources/{resource_id}') return response.status_code [2] 204
The function sends a DELETE request and checks if the status code equals 204 to confirm success.
Fill all three blanks to delete a user with authorization and handle errors properly.
def delete_user(user_id, token): headers = {'Authorization': f'Bearer [1]'} response = requests.[2](f'https://api.example.com/users/{user_id}', headers=headers) if response.status_code == [3]: return True else: return False
The function uses the token for authorization, sends a DELETE request, and checks for status code 204 to confirm deletion.