Skip to main content

Proxy-Session is a python module, helps to make a reliable proxy request to a HTTP server. Current version of this module is 0.1.1

Project description

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.

Project details


Download files

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

Source Distribution

Proxy-Session-0.1.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

Proxy_Session-0.1.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file Proxy-Session-0.1.1.tar.gz.

File metadata

  • Download URL: Proxy-Session-0.1.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for Proxy-Session-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3daabf05a5dfa381d4bd0bad2856c7bf8f7b1398e9c2b791be1b1d279c4b7f71
MD5 06884d70498f6fb5073a737d2050b37d
BLAKE2b-256 a2de450252dd15898ae0c019689f292c794b7cea04d74c37d6fcdf4f2b2b838e

See more details on using hashes here.

File details

Details for the file Proxy_Session-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: Proxy_Session-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for Proxy_Session-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1a7892b89e059494c2a5c88b58c055c0f9f48f3e3396ebd823842d28f4843944
MD5 956f8eb8084c49b1af5cce4bd1def5f8
BLAKE2b-256 717ec4fe6c9c0de6ec1e3e19b2fdc68ece773112c475efe91da0dff1d3d452c7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page