Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Proxy support? #446

Closed
ItsCEED opened this issue Nov 21, 2024 · 2 comments
Closed

Proxy support? #446

ItsCEED opened this issue Nov 21, 2024 · 2 comments

Comments

@ItsCEED
Copy link

ItsCEED commented Nov 21, 2024

Under the hood it seems is running httpx (i might be wrong?)

How can we set a proxy on client creation?

@MarshalX
Copy link
Owner

Yes it is httpx. I think you can implement your own request class with anything what you want using RequestBase. And then pass your request instance to the constructor of the client. Like request=myReq

@ItsCEED
Copy link
Author

ItsCEED commented Nov 21, 2024

Modifying the class directly did the job.

class AsyncRequest(RequestBase)

 def __init__(self, proxy_url: str = None) -> None:
        super().__init__()
        # Configure the AsyncClient with or without a proxy
        self._client = httpx.AsyncClient(
            follow_redirects=True,
            proxies={"all://": proxy_url} if proxy_url else None
        )

Worked this way with no issues:

import asyncio
from atproto import AsyncClient
from atproto_client.request import AsyncRequest

async def flow():
    proxy_url = "http://user:pass@host:port"

    custom_request = AsyncRequest(proxy_url=proxy_url)

    client = AsyncClient(request=custom_request)

    is_logged = await client.login(login="your_username", password="your_password", session_string="session")
    print("Login Response:", is_logged)

    post = await client.send_post(text="Hello World!")
    print("Post Response:", post)


asyncio.run(flow())

Question is, is there more efficient way to do it?

Repository owner locked and limited conversation to collaborators Nov 26, 2024
@MarshalX MarshalX converted this issue into discussion #467 Nov 26, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants