Questions tagged [sanic]

Sanic is a Python 3.6+ web server and web framework that’s written to go fast. It allows the usage of the async/await syntax added in Python 3.5, which makes your code non-blocking and speedy.

Sanic is a Flask-like Python 3.5+ web server that's written to go fast.

It supports async request handlers non-blocking using asyncio, uvloop and the async/await syntax from Python 3.5

Documentation: http://sanic.readthedocs.io/en/latest/

198 questions
25
votes
3 answers

How to reuse aiohttp ClientSession pool?

The docs say to reuse the ClientSession: Don’t create a session per request. Most likely you need a session per application which performs all requests altogether. A session contains a connection pool inside, connection reusage and keep-alives…
davidtgq
  • 3,780
  • 10
  • 43
  • 80
13
votes
5 answers

How to get access logs

Currently I am running my sanic(microframework) webservice with gunicorn as a daemon and I would like to save all logs in files(access and error) My config: reload = True daemon = True bind = '0.0.0.0:6666' worker_class =…
Creative crypter
  • 1,348
  • 6
  • 30
  • 67
11
votes
4 answers

How to perform file upload in Sanic

I am trying to perform file upload on Sanic but it is not working properly, the normal syntax for flask doesn't seem to work well with sanic here. I can't access even the filename or the save method to save the uploaded file to a given directory.
Jibin Mathew
  • 4,816
  • 4
  • 40
  • 68
11
votes
2 answers

Browser not sending cookie in subsequent request

Working with a project, where using cookie for user identification. When user arrives, it calls the service (which is running in localhost) and the service sending cookie with the response header looks like below: curl…
Alex Benz
  • 395
  • 4
  • 14
9
votes
2 answers

Session reusing in aiohhttp

I try to reuse HTTP-session as aiohttp docs advice Don’t create a session per request. Most likely you need a session per application which performs all requests altogether. But usual pattern which I use with requests lib doesn`t work: def…
Alex
  • 189
  • 1
  • 9
8
votes
2 answers

Python run_in_executor and forget?

How can I set a blocking function to be run in a executor, in a way that the result doesn't matter, so the main thread shouldn't wait or be slowed by it. To be honest I'm not sure if this is even the right solution for it, all I want is to have some…
Mojimi
  • 2,561
  • 9
  • 52
  • 116
8
votes
1 answer

Non-blocking requests in Sanic framework

I'm trying out Sanic and ran the Hello World app except I added a sleep in the request handler: @app.route("/") async def test(request): time.sleep(5) return json({"hello": "world"}) However, when I run this, it still blocks on each…
mart1n
  • 5,969
  • 5
  • 46
  • 83
7
votes
2 answers

How to use an aiohttp ClientSession with Sanic?

I am trying to understand what is the right way to use aiohttp with Sanic. From aiohttp documentation, I find the following: Don’t create a session per request. Most likely you need a session per application which performs all requests…
Tomer
  • 2,398
  • 1
  • 23
  • 31
6
votes
1 answer

aiohttp asyncio.TimeoutError from None using ClientSession

It's a weird error since when I try/catch it, it prints nothings. I'm using sanic server to asyncio.gather a bunch of images concurrently, more than 3 thousand images. I haven't got this error when dealing with a smaller sample size. Simplified…
Mojimi
  • 2,561
  • 9
  • 52
  • 116
6
votes
4 answers

Retrieving config from a blueprint in Sanic app

I have a Sanic application, and want to retrieve app.config from a blueprint as it holds MONGO_URL, and I will pass it to a repository class from the blueprint. However, I could not find how to get app.config in a blueprint. I have also checked…
skynyrd
  • 942
  • 4
  • 14
  • 34
5
votes
0 answers

Highly different CPU usage when proxying udp m2tp unicast stream to a streamed sanic.response

I have developed a proxy which lets me consume catchup video provided by my ISP as udp unicast m2tp streams through http. For that I am using python, asyncio and Sanic. It is working beautifully yet there is something I cannot explain. Some streams…
5
votes
1 answer

Sanic and Motor use different event loops

I am new to Sanic and I am trying to get it to work with Motor. I did manage to get everything to work in a single file, however, when I try it out within my project structure, I am running into the below issues. [2018-02-28 17:26:58 +0530] [3720]…
Mangesh
  • 137
  • 2
  • 9
5
votes
1 answer

I got a error [TypeError: 'coroutine' object is not iterable] when I used sanic and aiohttp

I built a small web server with Sanic, this is one of the views: @app.route("/query_video/", methods=["GET"]) async def video_query_views(request: Request): keyword = request.args.get("keyword", None) page = request.args.get("page", None) …
AngeloLi
  • 51
  • 1
  • 1
  • 3
5
votes
2 answers

Does Sanic have a 'url_for()' function (like in flask)?

I'm trying to port a simple flask app to sanic, working with the example for sanic and jinja. Does sanic have a url_for() function like flask?
user666
  • 5,231
  • 2
  • 26
  • 35
4
votes
3 answers

RedisClusterException: Too many connections in redis while using connection pool

I am using aredis to handle the connection pool. Following is how I instantiate redis connections in the main function - redis_conn = await asyncio.ensure_future(get_redis_conn(redis_host, loop)) Following is the co-routine definition -…
Sagar Grover
  • 65
  • 1
  • 9
1
2 3
13 14