Skip to content

Commit

Permalink
add proxy for account
Browse files Browse the repository at this point in the history
  • Loading branch information
Zkuns committed Feb 28, 2024
1 parent 1f0cfec commit f936e58
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions twitter/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, email: str = None, username: str = None, password: str = None
self.v2_api = 'https://twitter.com/i/api/2'
self.logger = self._init_logger(**kwargs)
self.proxies = proxies
self.session = self._validate_session(email, username, password, session, proxies=proxies, **kwargs)
self.session = self._validate_session(email, username, password, session, proxies, **kwargs)

def gql(self, method: str, operation: tuple, variables: dict, features: dict = Operation.default_features) -> dict:
qid, op = operation
Expand All @@ -51,8 +51,6 @@ def gql(self, method: str, operation: tuple, variables: dict, features: dict = O
'features': features,
'variables': Operation.default_variables | variables
}
if self.proxies:
self.session.proxies.update(self.proxies)
if method == 'POST':
data = {'json': params}
else:
Expand Down Expand Up @@ -617,7 +615,7 @@ def _init_logger(self, **kwargs) -> Logger:

@staticmethod
def _validate_session(*args, **kwargs):
email, username, password, session = args
email, username, password, session, proxies = args

# validate credentials
if all((email, username, password)):
Expand All @@ -635,14 +633,14 @@ def _validate_session(*args, **kwargs):

# try validating cookies dict
if isinstance(cookies, dict) and all(cookies.get(c) for c in {'ct0', 'auth_token'}):
_session = Client(cookies=cookies, follow_redirects=True)
_session = Client(cookies=cookies, follow_redirects=True, proxies=proxies)
_session._init_with_cookies = True
_session.headers.update(get_headers(_session))
return _session

# try validating cookies from file
if isinstance(cookies, str):
_session = Client(cookies=orjson.loads(Path(cookies).read_bytes()), follow_redirects=True)
_session = Client(cookies=orjson.loads(Path(cookies).read_bytes()), follow_redirects=True, proxies=proxies)
_session._init_with_cookies = True
_session.headers.update(get_headers(_session))
return _session
Expand Down

0 comments on commit f936e58

Please sign in to comment.