Giter Site home page Giter Site logo

aiohttp-session's Introduction

Aiohttp extension for aiogram

Using aiogram with aiohttp as http client

AiohttpSession represents a wrapper-class around ClientSession from aiohttp

Installation

pip install aiogram_aiohttp_session

Basic Usage example

from aiogram import Bot
from aiogram_aiohttp_session import AiohttpSession

session = AiohttpSession()
Bot('token', session=session)

Proxy requests in AiohttpSession

In order to use AiohttpSession with proxy connector you have to install aiohttp-socks

Create proxy session

from aiogram import Bot
from aiogram_aiohttp_session import AiohttpSession

session = AiohttpSession(proxy="protocol://host:port/")
Bot(token="bot token", session=session)

Note

Only following protocols are supported: http(tunneling), socks4(a), socks5 as aiohttp_socks documentation claims.

Authorization

Proxy authorization credentials can be specified in proxy URL or come as an instance of aiohttp.BasicAuth containing login and password.

Consider examples:

from aiohttp import BasicAuth
from aiogram_aiohttp_session import AiohttpSession

auth = BasicAuth(login="user", password="password")
session = AiohttpSession(proxy=("protocol://host:port", auth))
# or simply include your basic auth credential in URL
session = AiohttpSession(proxy="protocol://user:password@host:port")

Note

Library prefers BasicAuth over username and password in URL, so if proxy URL contains login and password and BasicAuth object is passed at the same time aiogram will use login and password from BasicAuth instance.

Proxy chains

Since aiohttp-socks supports proxy chains, you're able to use them in aiogram

Example of chain proxies:

from aiohttp import BasicAuth
from aiogram_aiohttp_session import AiohttpSession

auth = BasicAuth(login="user", password="password")
session = AiohttpSession(
    proxy={"protocol0://host:port0",
           "protocol1://user:password@host:port1",
           ("protocol2://host:port2", auth),}  # can be any iterable if not set
)

Rationale

Get rid of huge redundant code-base in main repo. Make an example of session extension for aiogram

aiohttp-session's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

kiniamogh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.