Skip to content

Instantly share code, notes, and snippets.

@cbarraford
Last active May 7, 2019 11:10
Show Gist options
  • Save cbarraford/07a003cf2cf5d1342b57082486c819dc to your computer and use it in GitHub Desktop.
Save cbarraford/07a003cf2cf5d1342b57082486c819dc to your computer and use it in GitHub Desktop.
Hug bug in 2.5.0 where POST requests don't never return
FROM python:alpine
RUN pip3 install hug==2.5.0
WORKDIR /app
EXPOSE 5454
CMD hug -p 5454 -f /app/main.py
import hug
@hug.post("/test", output=hug.output_format.json)
def post(body, response):
print(body)
return {'message': 'ok'}

When making a post request to Hug (v2.5.0), i never get a response. If I Ctrl-C the hug process, i get the following trackback...

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python3.7/site-packages/falcon/api.py", line 269, in __call__
    responder(req, resp, **params)
  File "/usr/local/lib/python3.7/site-packages/hug/interface.py", line 762, in __call__
    input_parameters = self.gather_parameters(request, response, context, api_version, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/hug/interface.py", line 611, in gather_parameters
    body = body_formatter(body, content_length=request.content_length, **content_params)
  File "/usr/local/lib/python3.7/site-packages/hug/input_format.py", line 43, in json
    return json_converter.loads(text(body, charset=charset))
  File "/usr/local/lib/python3.7/site-packages/hug/input_format.py", line 37, in text
    return body.read().decode(charset)
  File "/usr/local/lib/python3.7/socket.py", line 589, in readinto
    return self._sock.recv_into(b)
KeyboardInterrupt

Version 2.4.9 seems to work just fine.

Reproduction steps

  1. Build the docker image
docker build -t hug-bug --no-cache .
  1. Run hug
docker run --rm -it -v $(pwd):/app -p 5454:5454 hug-bug
  1. Curl our hug service
curl -H "Content-Type: application/json" -X POST -d '{"foo":"bar"}' "localhost:5454/test"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment