andelf / tronpy

TRON Python Client Library.
MIT License
212 stars 96 forks source link

Is it possible to use this library with a http/socks proxy? #19

Closed max-block closed 3 years ago

max-block commented 3 years ago

I thinks it's possible to solve this feature with the request_kwargs parameter.

Something like this:

class HttpProvider(BaseProvider):
    def __init__(self, node_url, request_kwargs=None):
        pass

What do you think about it? Do you want to add this feature, should I create a PR?

MioYvo commented 3 years ago

@max-block If you use AsyncHTTPProvider, yes. You can pass your own AsyncClient to AsyncHTTPProvider, like README.md mentioned, you can control async http client manually.

tronpy use httpx as async http client, more info about HTTP Proxying of httpx, check https://www.python-httpx.org/advanced/#http-proxying

Sample code like README I think(not tested)

......

async def transfer():
    _http_client = AsyncClient(limits=Limits(max_connections=100, max_keepalive_connections=20),
                               timeout=Timeout(timeout=10, connect=5, read=5),
                               proxies="http://localhost:8030")
    ......

Hope this helps :>

max-block commented 3 years ago

@MioYvo Thank you for the response! Yes, it's possible to use a proxy via AsyncHTTPProvider. But what's about a synchronous HTTPProvider?

Are there any reasons to use requests library for a sync mode? What do you think about using httpx for a sync mode as well? In this case it will be possible to use proxies in both modes: sync and async.

andelf commented 3 years ago

provider = HTTPProvider(....) provider.sess.proxies = {"https": "....", "http": "..."}

MioYvo commented 3 years ago

Yeah maybe we could replace requests with httpx, so we can use same method to deal with http

max-block commented 3 years ago

provider = HTTPProvider(....) provider.sess.proxies = {"https": "....", "http": "..."}

it works, thank you!