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 k3http
import urllib
import socket

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 (socket.error, 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 (socket.error, 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

k3http-0.1.5.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

k3http-0.1.5-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file k3http-0.1.5.tar.gz.

File metadata

  • Download URL: k3http-0.1.5.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for k3http-0.1.5.tar.gz
Algorithm Hash digest
SHA256 965cff6121b322e55110e8b796dab165b33ec9f3dbc86706a5ec1832a3d08612
MD5 4635c909fa267f526aa06476b8e00dca
BLAKE2b-256 5a758e83f317f809414073fa99c717bf656a1943326c771c1a951b4397e966cc

See more details on using hashes here.

File details

Details for the file k3http-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: k3http-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for k3http-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5d9feb1a15880175576c66502795f01bf4ffb6e8afb88eedfbdab6a5707e13e5
MD5 cab2a3d9e2bb45a17c826c417b7f4e61
BLAKE2b-256 b9326eef42b7c3b441e4a4271ab771d6aba3c84d08971d391df8deac7a3ff81f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page