Ctrl + K
DocumentationLog inGet started

tessl/pypi-w3lib

tessl install tessl/pypi-w3lib@2.3.0

Library of web-related functions for HTML manipulation, HTTP processing, URL handling, and encoding detection

Agent Success

Agent success rate when using this tile

84%

Improvement

Agent success rate improvement when using this tile compared to baseline

0.91x

Baseline

Agent success rate without this tile

92%

task.mdevals/scenario-5/

HTTP API Client Authenticator

Build a simple HTTP API client authentication module that handles user credentials and generates proper authorization headers for API requests.

Requirements

Authentication Header Generation

Your module should provide functionality to prepare authentication headers for HTTP requests to various APIs. The system needs to:

  • Accept user credentials (username and password)
  • Generate properly formatted authentication headers suitable for HTTP Basic Authentication
  • Support different character encodings for credentials (ASCII/Latin-1 and UTF-8)
  • Return headers in a format ready to be added to HTTP requests

API Endpoints Support

The module should support authentication for two different API services:

Standard ASCII API

  • Requires Basic Authentication
  • Uses standard ASCII/Latin-1 encoding for credentials
  • Returns authentication header as a dictionary with key "Authorization"

International API

  • Requires Basic Authentication
  • Supports international characters in usernames/passwords
  • Uses UTF-8 encoding for credentials
  • Returns authentication header as a dictionary with key "Authorization"

Test Cases

  • When authenticating to the Standard ASCII API with username "admin" and password "secret123", the returned header dictionary should contain an "Authorization" key with the correct Basic Authentication value @test

  • When authenticating to the International API with username "用户" (Chinese for "user") and password "пароль" (Russian for "password"), the returned header dictionary should contain an "Authorization" key with the correct UTF-8 encoded Basic Authentication value @test

  • The authentication header values should be properly formatted according to HTTP Basic Authentication standards (Base64 encoded username:password combination) @test

Implementation

@generates

API

def generate_standard_auth_header(username: str, password: str) -> dict:
    """
    Generate authentication header for Standard ASCII API.

    Args:
        username: The username for authentication
        password: The password for authentication

    Returns:
        Dictionary containing the Authorization header
    """
    pass

def generate_international_auth_header(username: str, password: str) -> dict:
    """
    Generate authentication header for International API with UTF-8 support.

    Args:
        username: The username for authentication (may contain international characters)
        password: The password for authentication (may contain international characters)

    Returns:
        Dictionary containing the Authorization header
    """
    pass

Dependencies { .dependencies }

w3lib { .dependency }

Provides web-related utility functions including HTTP authentication support.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/w3lib@2.3.x
tile.json