Coder Social home page Coder Social logo

asyncwebsockets's People

Contributors

belm0 avatar dlech avatar fuyukai avatar smurfix avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

asyncwebsockets's Issues

code in _specific is not correctly deployed

$ pip3 install git+https://github.com/Fuyukai/asyncwebsockets.git#egg=asyncwebsockets
Collecting asyncwebsockets from git+https://github.com/Fuyukai/asyncwebsockets.git#egg=asyncwebsockets
  Cloning https://github.com/Fuyukai/asyncwebsockets.git to /private/var/folders/ww/51xbs7nx6t16x7mh225q9x1h0000gn/T/pip-build-_dz2h9_l/asyncwebsockets
Requirement already satisfied: multio in /Users/john/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from asyncwebsockets)
Requirement already satisfied: wsproto>=0.11.0 in /Users/john/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from asyncwebsockets)
Requirement already satisfied: async_generator in /Users/john/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from asyncwebsockets)
Requirement already satisfied: yarl in /Users/john/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from asyncwebsockets)
Requirement already satisfied: h11~=0.7.0 in /Users/john/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from wsproto>=0.11.0->asyncwebsockets)
Requirement already satisfied: multidict>=4.0 in /Users/john/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from yarl->asyncwebsockets)
Requirement already satisfied: idna>=2.0 in /Users/john/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from yarl->asyncwebsockets)
Installing collected packages: asyncwebsockets
  Running setup.py install for asyncwebsockets ... done
Successfully installed asyncwebsockets-0.2.1.dev16
You are using pip version 9.0.3, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ pydoc3 asyncwebsockets
problem in asyncwebsockets - ModuleNotFoundError: No module named 'asyncwebsockets._specific'

exception for the example

When I run the example, it raises the exception:

....
  File "~/lib/python3.6/site-packages/trio/_ssl.py", line 416, in _check_status
    raise ClosedStreamError
trio.ClosedStreamError

Is this the expected behavior?

I'm using trio 0.3.0

import multio

from asyncwebsockets.client import connect_websocket
from asyncwebsockets.ws import WebsocketConnectionEstablished, WebsocketBytesMessage


async def test():
    sock = await connect_websocket("wss://echo.websocket.org", reconnecting=False)
    async for message in sock:
        print("Event received", message)
        if isinstance(message, WebsocketConnectionEstablished):
            await sock.send_message(b"test")

        elif isinstance(message, WebsocketBytesMessage):
            print("Got response:", message.data)
            await sock.close(code=1000, reason="Thank you!")


multio.init("trio")
multio.run(test)

receive_message()

It seems useful to offer receive_message() in addition to receiving by iteration. This would be in line with other async websocket API's such as aiohttp.

The use case is simple query-response sequences within a single task:

await ws.send_message('foo?')
reply = await ws.receive_message()

(using auto reconnect wouldn't make sense here)

cancel of open_websocket() during __aenter__ causes exception

I assume it's when cancel happens while waiting for ConnectionEstablished.

File "foo.py", line 50, in foo
  async with open_websocket(url) as ws:
File "/.../site-packages/async_generator/_util.py", line 34, in __aenter__
  return await self._agen.asend(None)
File "asyncwebsockets/asyncwebsockets/client.py", line 33, in open_websocket
  await ws.close()
File "asyncwebsockets/asyncwebsockets/_specific/trio.py", line 60, in close
  self._connection.close(code=code, reason=reason)
File "/.../site-packages/wsproto/connection.py", line 189, in close
  self._outgoing += self._proto.close(code, reason)
AttributeError: 'NoneType' object has no attribute 'close'

No link to documentation in readme

It took me a while to find the documentation (duck duck go struggled - had to use google), so it'd be helpful to have a link to it in the readme.

next_event() blocking when data is in receive buffer

I've seen this in two different programs now, both cases under Trio with plaintext websockets. (In one case I had an SSL server available and switching to wss worked fine.)

The behavior is that next_event() blocks indefinitely on await receive_some() when I know in fact the server has sent a response. Once the server subsequently sends more data (or a ping occurs), the pending data surfaces, although the newly sent data becomes stalled in the same way.

I found that lowering the receive_some() size masks the problem.

It's reproducible, I'll try to distill an example.

RFE: expose an idiomatic api for Ping/Pong

My use case involves handling Ping from a server. Currently I create the Pong payload and use internal attributes of websocket to send the reply.

    # code smell as it uses internal attributes
    # websocket.send assumes you want to send
    # text or binary...
    async def handle_server_ping(ws, item):
        pong = item.response()
        async with ws._send_lock:
            data = ws._connection.send(pong)
            await ws._sock.send(data)

HTTP HOST error

If I visit "ws://127.0.0.1:9222/devtools/page/D39BF37BAFD9C1E4983F9BFF46BCEB28", the HOST should be "127.0.0.1:9222".
But now the program is set to "127.0.0.1", causing me to connect to chrome's websocket debug Interface failed.

Should there be a Lock around the TCP sending part?

When multiple tasks are sending messages you can run into BusyResourceError as there is an await in the send() method.

trio-websocket encloses the send block in a stream so perhaps this library should do the same

No longer compatible with curio?

I was looking to see if there was any websockets library available for curio.

I saw this one, but upon further digging it seems anyio 3 drops support for curio. I notice that release 0.8.2 which is the latest on pypi only requires anyio > 2 which could theoretically work, but people are likely to get an anyio > 3 release when installing anyway (as a note, this a good reason to use the ~= specifier for compatibility, which pip has supported for yonks).

So I would merely suggest dropping the language on the readme, tags, etc that it's curio-compatible, be that as it may.

Readme basic usage doesn't work

Running the example in the 'Basic Usage' section of the readme raises the following exception:

AttributeError: 'Websocket' object has no attribute 'next_event'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.