racinette / websockets_proxy

Connect to websockets through a proxy server.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting error with missing open_timeout variable

awchiu23 opened this issue · comments

Hi racinette,

I really appreciate your work in enabling proxy support for websockets. I tried it today with the following installed:

websockets 12.0
websockets_proxy 0.1.0
python-socks 2.4.4

While testing, I'm getting the following error:

File "...\Lib\site-packages\websockets\legacy\client.py", line 646, in await_impl_timeout
async with asyncio_timeout(self.open_timeout):
^^^^^^^^^^^^^^^^^
AttributeError: 'ProxyConnect' object has no attribute 'open_timeout'

I'm following your examples when trying. Maybe I'm doing something wrong?

Any advise is appreciated, thanks.

Andrew

Nevermind.

I used:

ws = await proxy_connect(...)

which caused the error.

After changing to:

ws = proxy_connect(...)

The error is gone.

It seems like I cannot Send() using your websocket object .

await ws.send(json.dumps({'time':int(time.time()), 'channel':channel, 'event':'subscribe', 'payload':payload, 'auth':auth}))
      ^^^^^^^

AttributeError: 'ProxyConnect' object has no attribute 'send'

Is it possible to send message through your object?

Thanks!

proxy_connect returns the same object as the original websockets.connect, so you must be using it wrong. You should post a minimal reproducible example of your code, so that I can run it and test it. Otherwise, it's just guessing.

If you really want to return it from function, use it like so:

def GetWebsocket():
    return proxy_connect(proxy=XXX)

async def main():
    async with GetWebsocket() as ws:
         await ws.send("blablabla")

It should work.

Do not ask questions here, which have nothing to do with the library. It's not a library issue, it's a skill one. StackOverflow should be the way to go.

@racinette how can I run it with timeout?
I want to increase the timeout of connect
because sometimes, endpoint become lag and it will cost few minutes to connect
look like default timeout is 30-40second

when I try to run with wait_for

websocket = await asyncio.wait_for(proxy_connect(...), timeout=4*60)

I got same error with this issue

'ProxyConnect' object has no attribute 'open_timeout'

@yanghoxom you should try setting proxy_conn_timeout argument, as per docs.

In your example you set timeout to 4*60, which is 4 minutes, however, you do not want the timeout to be long.

I do not seem to understand the issue. I suppose setting the timeout to somewhere along the 10 seconds mark should do the trick.

@yanghoxom fixed in 0.1.2