Sanic: Exception occured while handling uri: unknown

Created on 24 Aug 2020  路  14Comments  路  Source: sanic-org/sanic

Describe the bug
Randomly I get the exception:

[2020-08-24 04:50:26 +0100] [2348] [ERROR] Exception occurred while handling uri: unknown
NoneType: None

Code snippet
No code as I don't know causes this error.

Expected behavior
No exception.

Environment (please complete the following information):

  • OS: Windows 10
  • Version: 19.12.2

Additional context
I've got a websocket server running in the same script but when receiving/connecting/sending messages, the exception isnt raised then, it's raised randomly.

question stale

Most helpful comment

I will try and add a best practices document for communication between two servers using a queue

I can do you one better. I am working on a user guide (will send you the repo) to hold lots of examples and a more tutorial style walk through of Sanic.

All 14 comments

What kind of exception handlers do you have? Is this a full blown app or an MVP? Possibly something in your Middleware is messing up the request object. Have you tried to narrow it down at all?

I've got no middleware & yes it is a MVP.

And exception handler? Is this some sort of event?

can you provide any kind of code snippet?

No code in particular causes this so I'm not sure what snippet of code to send, want the full code?

If you don't mind. It is near impossible to figure it out without knowing what you are running. 馃槵

If you would prefer to send privately, send me a private message on the forums

https://community.sanicframework.org

Here is my source code from the script that I get the error from: https://hastebin.com/nuhuwobugu.py

I stripped out everything unrelated to sanic, and it works fine: https://gist.github.com/sjsadowski/a2c5dc52967d3a68c0083370c1477334

I think your problem is with something not-sanic.

Also: windows support for sanic is best-effort, so there could be something else going on there.

Is there any way to just ignore these exceptions?

You are running two servers from the same loop? This is definitely a less than ideal setup. Two things:

  1. Sanic has websocket handlers. There is no need to run a seperate service.
  2. If you _need_ to keep it seperate (different domain/port/etc), then it should be done in a separate process.

I have not run the code to look at it, but I suspect this is a problem.


Last thing, running Sanic this way is less than ideal. I would not suggest using run_until_complete and run_forever unless you absolutely have to. For _most_ situations where you need to run something along side Sanic (and need access to the loop), it should be done in a listener.

Application developers should typically use the high-level asyncio functions, such as asyncio.run(), and should rarely need to reference the loop object or call its methods. This section is intended mostly for authors of lower-level code, libraries, and frameworks, who need finer control over the event loop behavior

Source

@ahopkins I will try and add a best practices document for communication between two servers using a queue. It seems like we're answering this question/pattern of thinking very often because of the assumption that in order to communicate, these things need to be running in the same loop in the same application.

I will try and add a best practices document for communication between two servers using a queue

I can do you one better. I am working on a user guide (will send you the repo) to hold lots of examples and a more tutorial style walk through of Sanic.

I'll put it there, seems like a great place for it.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings