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

fix: remove httpx's deprecated parameter proxies #231

Merged
merged 6 commits into from
Dec 4, 2024

Conversation

changchiyou
Copy link
Contributor

@changchiyou changchiyou commented Nov 29, 2024

Fix #230:

I can't find any usecase / demo with proxies parameter from docs, and it has already deprecated httpx. I think it's time to remove it from project.

(soft-removed with new exception raising)
@mahrtayyab
Copy link
Owner

mahrtayyab commented Nov 30, 2024

Removing proxy is not a good idea , #230 is about httpx proxies parameter being deprecated, not ours , we can simple use proxy with URL format instead of proxies.

httpx.Client(proxy='socks5://user:pass@host:port')

@changchiyou
Copy link
Contributor Author

changchiyou commented Nov 30, 2024

According to my study, currently tweety only use proxy parameter for proxies, I don't think proxy parameter is useful now since proxies has already been deprecated:

  1. src/tweety/init.py:

    class TwitterAsync(
    UserMethods, BotMethods, UpdateMethods, AuthMethods
    ):
    pass

  2. src/tweety/bot.py:

    tweety/src/tweety/bot.py

    Lines 15 to 18 in 991d431

    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):

    self._proxy = proxy.get_dict() if isinstance(proxy, Proxy) else proxy

    # self._captcha_solver = captcha_solver(self, self._proxy)

    self.request = self.http = Request(self, max_retries=10, proxy=self._proxy, captcha_solver=captcha_solver, **httpx_kwargs)

  3. src/tweety/http.py:

    def __init__(self, client, max_retries=3, proxy=None, captcha_solver=None, **kwargs):

    proxies=proxy,

@changchiyou
Copy link
Contributor Author

Removing proxy is not a good idea , #230 is about httpx proxies parameter being deprecated, not ours , we can simple use proxy with URL format instead of proxies.

httpx.Client(proxy='socks5://user:pass@host:port')

🤔 I think you are right, https://github.com/encode/httpx/releases/tag/0.26.0 says

The proxy argument was added. You should use the proxy argument instead of the deprecated proxies, or use mounts= for more complex configurations. (encode/httpx#2879)

And encode/httpx#2879 provided complete example code:

import httpx

# instead of 
# httpx.Client(proxies="http://127.0.0.1:80")
# and
# httpx.Client(proxies={"all://": "http://127.0.0.1:80"})
# do ...
client = httpx.Client(proxy="http://127.0.0.1:80")

@mahrtayyab
Copy link
Owner

Also need to make sure proxy is in correct format

ProxyTypes = Union["URL", str, "Proxy"]

changchiyou added a commit to changchiyou/wildrift-news-feeds that referenced this pull request Nov 30, 2024
changchiyou added a commit to changchiyou/wildrift-news-feeds that referenced this pull request Nov 30, 2024
changchiyou added a commit to changchiyou/wildrift-news-feeds that referenced this pull request Nov 30, 2024
@changchiyou
Copy link
Contributor Author

changchiyou commented Nov 30, 2024

@mahrtayyab Done, check with changchiyou/wildrift-news-feeds@4472a6d

@mahrtayyab mahrtayyab merged commit 8a329d1 into mahrtayyab:main Dec 4, 2024
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.

TypeError: AsyncClient.__init__() got an unexpected keyword argument 'proxies'
2 participants