benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf f12070cd-8001-50c3-9511-0e5dd17ccfa3

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import socket
import requests

def task_func(host):
    """
    This function resolves the IP address of the given host and then uses the IP address 
    to fetch geolocation information from the ipinfo.io API. The function is robust against
    various common errors, such as invalid hostnames, network issues, or problems with the 
    geolocation service.

    Parameters:
    host (str): The hostname to be resolved.

    Returns:
    dict: A dictionary containing the IP address and geolocation information if successful.

    Raises:
    ValueError: If 'host' is None or an empty string.
    ConnectionError: If there is a problem connecting to the geolocation service.

    Example:
    >>> result = task_func('google.com')
    >>> 'ip_address' in result and 'geolocation' in result
    True
    >>> task_func('')
    Traceback (most recent call last):
       ...
    ValueError: Host must be a non-empty string.
    
    Requirements:
    - socket
    - requests
    """

instruct prompt

This function resolves the IP address of the given host and then uses the IP address to fetch geolocation information from the ipinfo.io API. The function is robust against various common errors, such as invalid hostnames, network issues, or problems with the geolocation service.
The function should raise the exception for: ValueError: If 'host' is None or an empty string. ConnectionError: If there is a problem connecting to the geolocation service.
The function should output with:
    dict: A dictionary containing the IP address and geolocation information if successful.
You should write self-contained code starting with:

Code

import socket
import requests
def task_func(host):

code prompt

Code

import socket
import requests
def task_func(host):

entry point

task_func

libs

  • requests
  • socket

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import