Skip to content

fix: remove httpx's deprecated parameter proxies #231

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

Merged
merged 6 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/tweety/bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import warnings
from typing import Union, Type
from httpx._types import ProxyTypes
from httpx._config import Proxy as httpxProxy
from httpx._urls import URL
from .utils import (find_objects, AuthRequired, get_user_from_typehead, get_tweet_id, check_translation_lang,
is_tweet_protected, async_list)
from .types import (Proxy, TweetComments, UserTweets, Search, User, Tweet, Trends, Community, CommunityTweets,
Expand All @@ -15,12 +18,12 @@
class BotMethods:
LOGIN_URL = "https://api.x.com/1.1/onboarding/task.json?flow_name=login"

def __init__(self, session_name: Union[str, Session], proxy: Union[dict, Proxy] = None, captcha_solver: Type[BaseCaptchaSolver] = None, **httpx_kwargs):
def __init__(self, session_name: Union[str, Session], proxy: Union[ProxyTypes, None] = None, captcha_solver: Type[BaseCaptchaSolver] = None, **httpx_kwargs):
"""
Constructor of the Twitter Public class

:param: session_name: (`str`, `Session`) This is the name of the session which will be saved and can be loaded later
:param: proxy: (`dict` or `Proxy`) Provide the proxy you want to use while making a request
:param: proxy: (`ProxyTypes` or `None`) Provide the proxy you want to use while making a request
:param: captcha_solver: (`BaseCaptchaSolver`) Provide the instance of captcha solver class
which has two mandatory methods named `unlock`, `__call__`.
- both mandatory methods should accept at least one argument
Expand All @@ -34,7 +37,7 @@ def __init__(self, session_name: Union[str, Session], proxy: Union[dict, Proxy]
self._login_flow_state = None
self._last_json = {}
self._cached_users = {}
self._proxy = proxy.get_dict() if isinstance(proxy, Proxy) else proxy
self._proxy = proxy
self._event_builders = []
self._captcha_solver = None

Expand All @@ -44,6 +47,13 @@ def __init__(self, session_name: Union[str, Session], proxy: Union[dict, Proxy]
self.session = session_name
else:
self.session = FileSession(self, session_name)
if not (
isinstance(proxy, URL) or \
isinstance(proxy, str) or \
isinstance(proxy, httpxProxy) or \
proxy is None
):
raise ValueError("'proxy' argument must be ProxyTypes(URL | str | Proxy) or None")

if captcha_solver:
if not hasattr(captcha_solver, "unlock"):
Expand Down
2 changes: 1 addition & 1 deletion src/tweety/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, client, max_retries=3, proxy=None, captcha_solver=None, **kwa
'origin': 'https://x.com'
},
http2=True,
proxies=proxy,
proxy=proxy,
timeout=timeout,
follow_redirects=True,
**kwargs
Expand Down