Skip to main content

Proxy-Session

Proxy-Session is a python module, helps to make a reliable proxy request to a HTTP server.

Version

The current version is 0.1.1.

Installation

Using git

git clone https://github.com/antaripchatterjee/Proxy-Session
cd Proxy-Session
python setup.py install

Using pip

pip install Proxy-Session

Uninstallation

pip uninstall proxy_session

Platform Support

This is a cross-platform python module, provided the version of the python interpreter should be 3.6+.

API Reference

import requests
...
...

class ProxySession(requests.Session):
    def __init__(self, user_=None, pass_=None, socks=False):
        '''
        @param user_: str[None] -> Username for proxy authentication
        @param pass_: str[None] -> Password for proxy authentication
        @param socks: bool[False] -> If True, it will perform a socks5
                authentication, given the user_ and pass_ has been
                provided. If False, it will perform a basic authent-
                ication will be performed, provided the value of
                user_ and pass_.
        '''
        super(ProxySession, self).__init__()
        ...
        ...
    ...
    ...
    def make_request(self, url, method='GET', timeout=ProxySessionTimeout.SHORT_TIMEOUT, log = True, max_attempt = 100, **kwargv):
        '''
        @param url: str -> The target URL
        @param method: str[GET] -> The HTTP method to be called
        @param timeout: int[5] -> The timeout value, for the proxy request
        @param log: bool[True] -> It will log the necessary information
        @param max_attempt: int[100] -> Maximum number of attempt to reach the target URL,
                must be a positve integer
        @param **kwargv -> Other keyword arguments, which will be passed to requests.request
                method

        @return -> It will always return the tuple of two element, response and proxy_url
                On success, it will return the reponse object, returned by the method call and
                the proxy url. If the random proxy selection is made, it will return the proxy
                url as a string, otherwise it will be same as keyword argument "proxies". 
                On Failure after maximum attempts, it will return a Response object, having
                status_code -1 with empty content. The proxy url will be null in this case.
        '''
        ...
        ...
    ...
    ...

Find the full source code from GitHub.

If you need to make a request using socks proxy, make sure you install PySocks. Alternatively just run the below command.

pip install requests[socks]

If you pass keyword argument proxies to the ProxySession.make_request method(like requests.request(...)), it will prevent any random proxy selection.

The random proxies are scrapped from Free Proxy List - Just Checked Proxy List. This module provides a reliable way to find a free and live proxy server, however, it does not evaluate any security of the proxy server, so it does not guarantee you about your personal and/or confidential data. It is always better to use a paid proxy, instead of a free proxy.

Usage

from sys import stderr
from proxy_session import ProxySession
from proxy_session import ProxySessionTimeout

if __name__ == '__main__':
    with ProxySession() as ps:
        error_ = ps.error
        if error_:
            print('Error Status: ', error_[0], file=stderr)
            print('Error:\n' + error_[1], file=stderr)
        response, proxy_addr = ps.make_request('https://httpbin.org/ip', timeout=ProxySessionTimeout.LONG_TIMEOUT, log=True)
        if response.status_code == 200:
            print(f'Response Content:\n{response.text}')
            print(f'Proxy URL: {proxy_addr}')
        else:
            print(f'{response}')

The above code generated the below output, when I tested it.

Trying random free proxy[https]: http://103.109.58.102:46523
Trying random free proxy[https]: http://157.230.103.189:36366
Trying random free proxy[https]: http://85.15.152.39:3128
Response Content:
{
  "origin": "85.15.152.39"
}

Proxy URL: http://85.15.152.39:3128

License

Python module Proxy-Session comes with MIT License.

Metadata

Release files for Proxy-Session 0.1.1

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

Source distribution (sdist)

Source distribution for Proxy-Session 0.1.1
File Size Uploaded Provenance Actions
Proxy-Session-0.1.1.tar.gz 6.4 kB Without provenance Details for Proxy-Session-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for Proxy-Session 0.1.1
File Interpreter ABI Platform Actions
Proxy_Session-0.1.1-py3-none-any.whl Python 3 none any Details for Proxy_Session-0.1.1-py3-none-any.whl

Total release size: 13.3 kB

Release files / Proxy-Session-0.1.1.tar.gz

Download URL Proxy-Session-0.1.1.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3daabf05a5dfa381d4bd0bad2856c7bf8f7b1398e9c2b791be1b1d279c4b7f71
BLAKE2b-256 checksum
How to use checksums
a2de450252dd15898ae0c019689f292c794b7cea04d74c37d6fcdf4f2b2b838e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1

Release files / Proxy_Session-0.1.1-py3-none-any.whl

Download URL Proxy_Session-0.1.1-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a7892b89e059494c2a5c88b58c055c0f9f48f3e3396ebd823842d28f4843944
BLAKE2b-256 checksum
How to use checksums
717ec4fe6c9c0de6ec1e3e19b2fdc68ece773112c475efe91da0dff1d3d452c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1

Security for Proxy-Session 0.1.1

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.

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