We find that 'httplib' must work in blocking mode and it can not have a timeout when recving response.
Project description
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 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
Project details
Release history Release notifications | RSS feed
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.0.tar.gz
(8.0 kB
view details)
Built Distribution
File details
Details for the file k3http-0.1.0.tar.gz
.
File metadata
- Download URL: k3http-0.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7a28bb863de1f30f76256f98a72556bd6b633121931a627ebeaf3acf7f4897e |
|
MD5 | af34f973b0bd19457fd257d07fe239e7 |
|
BLAKE2b-256 | 2a70a7f471c3ac5d18a16b8d27e0a737b09b889e3f71eb1bdc5054cdc0abd5f4 |
File details
Details for the file k3http-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: k3http-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dcb50774bbeeb33792cfdcda78fda9099b9f9268f156f42a3096e34e3425891 |
|
MD5 | f1438b60fa694c72a900e1bddd7fcd59 |
|
BLAKE2b-256 | 2048e54ef5bc0b6c3be24acb342ee9e091fdeb96f1c5bd5aa17e564aef720eb0 |