k3http
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.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| k3http-0.1.8.tar.gz | 13.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| k3http-0.1.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.3 kB
Release files / k3http-0.1.8.tar.gz
| Download URL | k3http-0.1.8.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f52ceac407d67abfbe1d2e5f26a2c790fd70ca59c8cf4a7eeb62141dd7a4f8b2
|
|
BLAKE2b-256 checksum How to use checksums |
68f326982ab61a421b1d2580ee1f2ed0d828746a214eff92699f6c9dee0c3c92
|
| 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.8-py3-none-any.whl
| Download URL | k3http-0.1.8-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c84d8653268c6ce3d72fa0c9f8472bfbb0fe0d532a568f2f9f0123f2ee70b864
|
|
BLAKE2b-256 checksum How to use checksums |
ecc2249f15047f550f156c53780e8308fe46e7a9e2121610697a9cf81e63eab0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|