-
Under the hood it seems is running httpx (i might be wrong?) How can we set a proxy on client creation? |
Beta Was this translation helpful? Give feedback.
Answered by
ItsCEED
Nov 21, 2024
Replies: 2 comments 1 reply
-
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 |
Beta Was this translation helpful? Give feedback.
0 replies
-
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? |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
MarshalX
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modifying the class directly did the job.
Worked this way with no issues: