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

Add proxy, more session control #278

Closed
wants to merge 3 commits into from
Closed

Add proxy, more session control #278

wants to merge 3 commits into from

Conversation

makarworld
Copy link
Contributor

@makarworld makarworld commented Jul 4, 2023

Changes:

  • add proxy support to all requests
  • add cookies arg to init (if user saved session and want continue with them)
  • add autologout arg to init (if user want to save cookies and use it again later)
  • edit login method, if user provide username, password and steam guard when initialize class, method should not request
    them
  • edit login method, if session is alive, skip login method

Example:

from steampy.client import SteamClient

client = SteamClient(
    api_key='XXXXX5FXXDDXXXXXABECXXB0C86XXXXX', 
    username='steam_login', 
    password='steam_password', 
    steam_guard='account.maFile',
    proxies={
        "http": "http://login:password@host:port",
        "https": "http://login:password@host:port",
    }, 
    autologout = False)

client.login()
print(client.is_session_alive())

Session Control:

Also i add option autologout in __init__ function for more session control.
When autologout is True, session will be ended with program end
When autologout is False, session will be not end and you may re-use cookies later

Now you can save session cookies and re-use it later.

import json
cookies = client._session.cookies.get_dict()
with open('steam_cookies.json', 'w', encoding='utf-8') as f:
    json.dump(f, cookies)

re-use example:

from steampy.client import SteamClient
import json

with open('steam_cookies.json', 'r', encoding='utf-8') as f:
    cookies = json.load(f)
    
client = SteamClient(
    api_key = ..., 
    username = ..., 
    password = ..., 
    steam_guard = ...,
    proxies = ...,
    cookies = cookies,
    autologout = False)
    
print(client.is_session_alive())

if proxy_status is True:
self._session.proxies.update(proxies)

self.steam_guard = guard.load_steam_guard(steam_guard)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont like it readed here, it is loaded in login function and thus SteamClient can be used for some cases with API key and without guard. Guard can be hard to obtain so this is braking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@bukson
Copy link
Owner

bukson commented Sep 14, 2023

Please make 1 commit out of all those changes so in any case it is easily to revert it.

@makarworld
Copy link
Contributor Author

Please make 1 commit out of all those changes so in any case it is easily to revert it.

Okay

@bukson
Copy link
Owner

bukson commented Sep 14, 2023

I have a small problem with rebasing it with 1 commit onto current master, I will try to deal with it next week and make new version 0.92 of steampy when it is ready.

@bukson bukson closed this Sep 14, 2023
@bukson bukson reopened this Sep 14, 2023
@bukson
Copy link
Owner

bukson commented Sep 18, 2023

Ok merged it manually with master, closing this.

Autologout variable was delete, if you dont want to log out, just dont use with statement.

@bukson bukson closed this Sep 18, 2023
bukson pushed a commit that referenced this pull request Sep 19, 2023
bukson pushed a commit that referenced this pull request Sep 19, 2023
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.

2 participants