Comments (4)
Ohh, yeah looks like get_body() was a failed experiment - bridging a non-coroutine to a coroutine.
The Problem:
In short, to speed up processing the request, the HTTP headers are read and then the middleware is processed immediately. The res.body attribute is a Future, allowing the backend to cache the (potentially large) file while the webapp is running, until the body is requested. This was the purpose of get_body(), to get the value of the future without having your function be a coroutine.
The problem is, there is no way to do that. I was trying to start a new loop, obviously it didn't like that.
The Solution:
Coroutines are supported as Growler middleware, and you're using python3.5 so it's super easy!
Make post_test
asynchronous by doing something like:
@app.post('/data')
async def post_test(req, res):
print(await req.body)
res.send_text("OK!\n")
That should work for you (also add the res.send_text
so the curl command doesn't print the 404 error).
from growler.
For python 3.4 compatibility, this works:
@app.post('/data')
@asyncio.coroutine
def post_test(req, res):
data = yield from req.body
print(data)
res.send_text("OK")
I'm thrilled you think Growler can help you with your project, but please note that it is still a baby project and is missing a lot of functionality. I'd really appreciate any other questions or bugs you find.
from growler.
Thank you for the answer. I see that it`s baby project. I need just a few things, but with a lot of middlewares. Tbh flask middlewares are awful, while yours are look like node or golang one. Thank you one more time.
from growler.
I'm running into a similar problem, but instead of crashing I'm just waiting forever for the body to load. This happens when I post all different types of files to my POST endpoint and of various of sizes. It works quickly for smaller files but when I send pdfs and pngs that are only 320K it hangs.
from growler.
Related Issues (16)
- please suggest an ORM/db layer HOT 4
- Consider an integration with uvloop HOT 2
- Implement ETag HOT 3
- Example in README.md doesn't work? HOT 1
- routes using @routerclass decorator HOT 2
- Using Uvloop in Growler HOT 2
- GrowlerHTTPResponder' object has no attribute 'client_query' HOT 1
- Replace root logger. HOT 1
- Clarify how to use the ext namespace and RendererEngine HOT 4
- Refactor pytest fixtures into a pytest-growler plugin HOT 3
- Are views a coroutines? HOT 2
- Suggestion: remove growler.ext mechanism HOT 2
- Add SSL Support HOT 4
- Is this project production ready? HOT 3
- Handle binary data uploads HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from growler.