sshtunnel-requests
Install
$ pip install sshtunnel-requests
Usage
import sshtunnel_requests
requests = sshtunnel_requests.from_url(
'ssh://username@host:port', '<path>/<to>/private_key')
resp = requests.get('http://httpbin.org/ip')
print(resp.status_code)
# 200
print(resp.json())
# public IP of ssh-server machine
reused created tunnel to request more then once:
import sshtunnel_requests
requests = sshtunnel_requests.from_url(
'ssh://username@host:port', '<path>/<to>/private_key')
urls = [
'http://httpbin.org/headers',
'http://httpbin.org/ip',
'http://httpbin.org/user-agent',
'http://httpbin.org/uuid',
]
for url in urls:
resp = requests.get(url)
print(resp.json())
thread example:
import sshtunnel_requests
requests = sshtunnel_requests.from_url(
"ssh://<username>@<ssh server host>[:<port>]",
"<path>/<to>/<private key>"
)
urls = [
'http://httpbin.org/headers',
'http://httpbin.org/ip',
'http://httpbin.org/user-agent',
'http://httpbin.org/uuid',
]
from concurrent.futures import ThreadPoolExecutor
from concurrent.futures import as_completed
results = []
with ThreadPoolExecutor(max_workers=3) as pool:
futures = []
for url in urls:
f = pool.submit(
lambda _req, _url: _req.get(_url),
requests, url
)
futures.append(f)
done_iter = as_completed(futures)
for future in done_iter:
response = future.result()
results.append(response.json())
from pprint import pp
for result in results:
pp(result)
use session:
import sshtunnel_requests
session = sshtunnel_requests.Session.from_url(
"ssh://<username>@<ssh server host>[:<port>]",
"<path>/<to>/<private key>"
)
assert session.cookies.values() == list()
resp = session.get(
'http://httpbin.org/cookies/set/sessioncookie/123456789'
)
assert resp.json() == {'cookies': {'sessioncookie': '123456789'}}
assert session.cookies.values() == ['123456789']
resp = session.get('http://httpbin.org/ip')
assert 'Cookie' in resp.request.headers
assert resp.request.headers['Cookie'] == 'sessioncookie=123456789'
print(resp.json())
# public IP of ssh-server machine
Features
simply use sshtunnel and requests to request HTTP server in internal networking.
caching ssh tunnel connection to reused next requests of the same server.
automatic release connection if the ssh tunnel connection has not been used some time (without any consideration of memory leak and fd leak)
(thread) concurrent support of the same connection.
Test
$ cd e2e_tests && docker-compose up -d; cd ..
$
$ `which python` -m pip install -U pip
$ pip install .
$ pip install -r requirements_test.txt
$
$ # cd e2e_tests && docker-compose logs ssh; cd ..
$ # cd e2e_tests && docker-compose exec ssh cat /config/logs/openssh/current; cd ..
$ chmod 600 ./e2e_tests/ssh-server-config/ssh_host_rsa_key
$ # ssh -o "StrictHostKeyChecking=no" linuxserver@127.0.0.1 -p 2223 -i ./e2e_tests/ssh-server-config/ssh_host_rsa_key -v "uname -a"
$ pytest e2e_tests
Metadata
Release files for sshtunnel-requests 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sshtunnel_requests-0.1.3.tar.gz | 8.1 kB | Without provenance | Details for sshtunnel_requests-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sshtunnel_requests-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for sshtunnel_requests-0.1.3-py3-none-any.whl |
Total release size: 15.8 kB
Release files / sshtunnel_requests-0.1.3.tar.gz
| Download URL | sshtunnel_requests-0.1.3.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f0f6ff818d295c4ccc8d523f3dd0f9c1bc9fad4879da57b97da4758c4e68c9de
|
|
BLAKE2b-256 checksum How to use checksums |
72de8d64d6a748f3bf237d40285aa5844020696336c87d75a931a585c504c8c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
|
Release files / sshtunnel_requests-0.1.3-py3-none-any.whl
| Download URL | sshtunnel_requests-0.1.3-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8594927b0fb507768a72ab92b99a915f2fb926838c338200a388b4f7e69a59f8
|
|
BLAKE2b-256 checksum How to use checksums |
c883fcc32592eb2ebecc50fe6833e2b72628263b70301d058ef9fb9de7d91156
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
|
Security for sshtunnel-requests 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.