benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf f88e07b1-8e3e-5cad-8609-c2b0bb8a6d3f

Problem

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

complete prompt

import json
import urllib.parse
import hmac
import hashlib

def task_func(req_data, secret_key):
    """
    Signs the specified request data with a secret key using HMAC SHA256, then URL encodes the signature and replace spaces with '+'.

    Parameters:
        req_data (dict): The request data to be signed. It should be a dictionary.
        secret_key (str): The secret key used for signing the request data.

    Returns:
        str: The URL encoded HMAC signature of the request data.

    Raises:
        TypeError: If `req_data` is not a dictionary.

    Requirements:
    - json
    - urllib.parse
    - hmac
    - hashlib

    Examples:
    >>> secret_key = 'my_secret_key'
    >>> isinstance(task_func({'test': 'just a test'}, secret_key), str)
    True
    >>> isinstance(task_func({'another': 'data', 'key': 123}, secret_key), str)
    True
    """

instruct prompt

Signs the specified request data with a secret key using HMAC SHA256, then URL encodes the signature and replace spaces with '+'.
The function should raise the exception for: TypeError: If `req_data` is not a dictionary.
The function should output with:
    str: The URL encoded HMAC signature of the request data.
You should write self-contained code starting with:

Code

import json
import urllib.parse
import hmac
import hashlib
def task_func(req_data, secret_key):

code prompt

Code

import json
import urllib.parse
import hmac
import hashlib
def task_func(req_data, secret_key):

entry point

task_func

libs

  • urllib
  • hmac
  • hashlib
  • json

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