Skip to main content

k3http

Action-CI Documentation Status Package

We find that 'httplib' must work in blocking mode and it can not have a timeout when recving response.

k3http is a component of pykit3 project: a python3 toolkit set.

HTTP/1.1 client

Use this module, we can set timeout, if timeout raise a 'socket.timeout'.

Install

pip install k3http

Synopsis

import urllib

import k3http

headers = {
    "Host": "127.0.0.1",
    "Accept-Language": "en, mi",
}

try:
    h = k3http.Client("127.0.0.1", 80)

    # send http reqeust without body
    # read response status line
    # read response headers
    h.request("/test.txt", method="GET", headers=headers)

    status = h.status
    # response code return from http server, type is int
    # 200
    # 302
    # 404
    # ...

    res_headers = h.headers
    # response headers except status line
    # res_headers = {
    #   'Content-Type': 'text/html;charset=utf-8',
    #   'Content-Length': 1024,
    #   ...
    # }

    # get response body
    print(h.read_body(None))
except (OSError, k3http.HttpError) as e:
    print(repr(e))


content = urllib.urlencode({"f": "foo", "b": "bar"})
headers = {
    "Host": "www.example.com",
    "Content-Type": "application/x-www-form-urlencoded;charset=utf-8",
    "Content-Length": len(content),
}

try:
    h = k3http.Client("127.0.0.1", 80)

    # send http reqeust
    h.send_request("http://www.example.com", method="POST", headers=headers)

    # send http request body
    h.send_body(content)

    # read response status line and headers
    status, headers = h.read_response()

    # read response body
    print(h.read_body(None))
except (OSError, k3http.HttpError) as e:
    print(repr(e))

Author

Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Copyright and License

The MIT License (MIT)

Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Metadata

Release files for k3http 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for k3http 0.1.9
File Size Uploaded
k3http-0.1.9.tar.gz 13.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for k3http 0.1.9
File Interpreter ABI Platform
k3http-0.1.9-py3-none-any.whl Python 3 none any Details

Total release size: 22.5 kB

Release files / k3http-0.1.9.tar.gz

Download URL k3http-0.1.9.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6f513a5c1f661e539eb4d293b5634250f4c0469416e44a821311d72b26cb17f6
BLAKE2b-256 checksum
How to use checksums
4a1a511ea0fa72709e2b20bf67433ade8f80eddbc99ac965b8f3892d1e4d6291
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / k3http-0.1.9-py3-none-any.whl

Download URL k3http-0.1.9-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7969eff002165612924b4cfb63a10841e0dbeeef6d694338a59e201994d0fe3
BLAKE2b-256 checksum
How to use checksums
c9b1d3b1024f1aafa4dffbf0400c7637e0b30ee5678a1d3b2e8256c53f88fda6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

0.1.10

2 release files

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page