Sanic: ValueError: too many values to unpack (expected 2)

Created on 1 Dec 2017  路  12Comments  路  Source: sanic-org/sanic

When I use https://github.com/channelcat/sanic/wiki/Examples#motor, It traceback this error.

[2017-12-01 11:22:28 +0800] [16395] [ERROR] Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sanic/server.py", line 340, in write_response
    self.log_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sanic/server.py", line 317, in log_response
    if self.request.ip:
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sanic/request.py", line 172, in ip
    self._get_address()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sanic/request.py", line 190, in _get_address
    self._ip, self._port = self._socket
ValueError: too many values to unpack (expected 2)

Most helpful comment

Let's give @seemethere a few more days, otherwise I'll look into making a release.

All 12 comments

It seem like the uvloop get more info from transport extra.
https://github.com/channelcat/sanic/blob/master/sanic/request.py#L187
Maybe It better way to unpack the information.

    def _get_address(self):
        self._socket = (self.transport.get_extra_info('peername') or
                        (None, None))
        self._ip = self._socket[0]
        self._port = self._socket[1]

I have observed this error message after a recent python update that did not involve updating sanic, so it is a dependency that has changed.

I remark that the server works as expected in spite of the error message in the log.

This error can easily be reproduced by passing host="localhost" to the run argument.

As a work around, passing host="0.0.0.0" instead of host="localhost" gets rid of the error message.

I can't actually reproduce this. @jmoraleda are you able to test using the master branch? The logic referenced in https://github.com/channelcat/sanic/issues/1041#issuecomment-348392607 has already been implemented, so I think this is probably just an issue with the latest release, but not the master branch.

Thank you @r0fls. I have not tried the master branch. This code reproduces it on version 0.7.0 (the latest on pypi):

from sanic import Sanic
from sanic.response import json

app = Sanic()

@app.route("/")
async def test(request):
    return json({"hello": "world"})

if __name__ == "__main__":
    app.run(host="localhost", port=8010)

@r0fls: can you release minor version on pypi with this fix?

I can get on that.

@r0fls: can you release minor version on pypi with this fix? we really need this )
@seemethere maybe you can get on that ? ))

@metron8 as mentioned in #1134 , for now you can use the following command to get the latest version of Sanic:

pip install git+https://github.com/channelcat/sanic.git@b671546

note that if you run pip freeze then it will still tagged as sanic==0.0.7 , so it may ruined your deployment. You can replace your requirements.txt manually to use the git url instead.

Let's give @seemethere a few more days, otherwise I'll look into making a release.

@r0fls Are we past "a few more days" yet? o:)

I have this issue with the most recent PyPI version (0.7.0).

I think this should be resolved with 0.8.0

Was this page helpful?
0 / 5 - 0 ratings