Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use a factory method to instantiate sessions #2195

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Henkhogan
Copy link

Currently there is no way to customize the instantiation of session objects. I would need to use a dedicated proxy for the connections to insta.

If you'd like me to add some tests or docu, let me know.

Cheers

@aandergr
Copy link
Member

I like this approach.

This would introduce a way to also cleanly set custom session parameters, like SSL verification (suggested in #2221), or the request timeout (#330, #422), without that we need to pass-through and implement each of those parameters.

With the current implementation suggestion I am wondering how the user would actually override the session factory. Maybe InstaloaderContext and Instaloader should provide a parameter to specify the factory.

The handling of the request timeout might also be refactored to be done in the new session factory.

@Henkhogan
Copy link
Author

I currently use it like that

def session_factory(self: InstaloaderContext):
    session = Session()
    session.trust_env = False
    return session

def instaloader_factory(max_connection_attempts=10):
    InstaloaderContext.session_factory = session_factory
    return Instaloader(compress_json=False, quiet=True, max_connection_attempts=max_connection_attempts)

which is still ugly but does that job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants