-
-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
disabling wsgi interface fails under python3 #1377
Comments
This also occurs for me, not tested under other Python versions. Example server setup, based on my own: cherrypy.config.update({'global': {
'server.socket_host': '0.0.0.0',
'server.socket_port': 8081,
'server.https.socket_host': '0.0.0.0',
'server.https.socket_port': 444,
'server.https.ssl_module': 'builtin',
'server.https.ssl_certificate': 'example_cert.pem',
'server.https.ssl_private_key': 'example_key.pem',
'server.https.ssl_certificate_chain' : 'example_chain.pem',
}})
from cherrypy._cpnative_server import CPHTTPServer
for s in (cherrypy.server, *cherrypy.servers.values()):
s.httpserver = CPHTTPServer(s) Trace: >python -mexample_http_server
[26/May/2016:18:41:41] ENGINE Bus STARTING
[26/May/2016:18:41:41] ENGINE Started monitor thread 'Autoreloader'.
[26/May/2016:18:41:41] ENGINE Started monitor thread '_TimeoutMonitor'.
[26/May/2016:18:41:42] ENGINE Serving on http://0.0.0.0:8081
[26/May/2016:18:41:42] ENGINE Serving on https://0.0.0.0:444
[26/May/2016:18:41:42] ENGINE Bus STARTED
...making a request to either server...
[26/May/2016:18:41:42] NATIVE_ADAPTER Traceback (most recent call last):
File "C:\Python35\lib\site-packages\cherrypy\_cpnative_server.py", line 27, in respond
sn = cherrypy.tree.script_name(req.uri or "/")
File "C:\Python35\lib\site-packages\cherrypy\_cptree.py", line 257, in script_name
path = path[:path.rfind("/")]
TypeError: a bytes-like object is required, not 'str'
ValueError('invalid literal for int() with base 10: "b\'5"',)
Traceback (most recent call last):
File "C:\Python35\lib\site-packages\cherrypy\_cpnative_server.py", line 27, in respond
sn = cherrypy.tree.script_name(req.uri or "/")
File "C:\Python35\lib\site-packages\cherrypy\_cptree.py", line 257, in script_name
path = path[:path.rfind("/")]
TypeError: a bytes-like object is required, not 'str'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python35\lib\site-packages\cherrypy\wsgiserver\wsgiserver3.py", line 1091, in communicate
req.respond()
File "C:\Python35\lib\site-packages\cherrypy\wsgiserver\wsgiserver3.py", line 879, in respond
self.server.gateway(self).respond()
File "C:\Python35\lib\site-packages\cherrypy\_cpnative_server.py", line 88, in respond
self.send_response(s, h, b)
File "C:\Python35\lib\site-packages\cherrypy\_cpnative_server.py", line 101, in send_response
req.send_headers()
File "C:\Python35\lib\site-packages\cherrypy\wsgiserver\wsgiserver3.py", line 935, in send_headers
status = int(self.status[:3])
ValueError: invalid literal for int() with base 10: "b'5"
...NATIVE_ADAPTER traceback repeated 5 more times... I followed the docs to the letter, so I'm not entirely sure what the issue is. |
I can confirm this issue persists even after the wsgiserver refactor: File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/_cpnative_server.py", line 27, in respond
sn = cherrypy.tree.script_name(req.uri or '/')
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/_cptree.py", line 259, in script_name
path = path[:path.rfind('/')]
TypeError: a bytes-like object is required, not 'str'
ValueError('invalid literal for int() with base 10: "b\'5"',)
Traceback (most recent call last):
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/_cpnative_server.py", line 27, in respond
sn = cherrypy.tree.script_name(req.uri or '/')
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/_cptree.py", line 259, in script_name
path = path[:path.rfind('/')]
TypeError: a bytes-like object is required, not 'str'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/wsgiserver/__init__.py", line 1408, in communicate
req.respond()
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/wsgiserver/__init__.py", line 862, in respond
self.server.gateway(self).respond()
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/_cpnative_server.py", line 88, in respond
self.send_response(s, h, b)
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/_cpnative_server.py", line 101, in send_response
req.send_headers()
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/wsgiserver/__init__.py", line 923, in send_headers
status = int(self.status[:3])
ValueError: invalid literal for int() with base 10: "b'5" |
Hmm.. What about now + cheroot? |
Looks like this bug is still there. I just hit it with Python 3.6.5 and CherryPy 15.0.0. Using the documentation's example: import cherrypy
class Root(object):
@cherrypy.expose
def index(self):
return "Hello World!"
if __name__ == '__main__':
from cherrypy._cpnative_server import CPHTTPServer
cherrypy.server.httpserver = CPHTTPServer(cherrypy.server)
cherrypy.quickstart(Root(), '/') the stack trace I get is: [23/May/2018:10:21:16] NATIVE_ADAPTER Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/cherrypy/_cpnative_server.py", line 30, in respond
sn = cherrypy.tree.script_name(req.uri or '/')
File "/usr/local/lib/python3.6/dist-packages/cherrypy/_cptree.py", line 268, in script_name
path = path[:path.rfind('/')]
TypeError: a bytes-like object is required, not 'str'
ValueError('invalid literal for int() with base 10: "b\'5"',)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/cherrypy/_cpnative_server.py", line 30, in respond
sn = cherrypy.tree.script_name(req.uri or '/')
File "/usr/local/lib/python3.6/dist-packages/cherrypy/_cptree.py", line 268, in script_name
path = path[:path.rfind('/')]
TypeError: a bytes-like object is required, not 'str'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/cheroot/server.py", line 1193, in communicate
req.respond()
File "/usr/local/lib/python3.6/dist-packages/cheroot/server.py", line 997, in respond
self.server.gateway(self).respond()
File "/usr/local/lib/python3.6/dist-packages/cherrypy/_cpnative_server.py", line 91, in respond
self.send_response(s, h, b)
File "/usr/local/lib/python3.6/dist-packages/cherrypy/_cpnative_server.py", line 105, in send_response
req.send_headers()
File "/usr/local/lib/python3.6/dist-packages/cheroot/server.py", line 1061, in send_headers
status = int(self.status[:3])
ValueError: invalid literal for int() with base 10: "b'5" |
@jaraco turns out, there's incorrect processing of bytes vs str in several places over this module.
It tried to
This originates in this line:
|
As I'm trying to replicate the issue with that patch above, I'm running into another error (#1697):
|
@jaraco yes, exactly. that's why it's WIP |
You could try Python 3.6 for now |
I've fixed #1697 and now I'm getting the same result on my test branch on Python 3.7 and 3.6: cherrypy bugfix/1377-add-test $ tox -e py36 -- test-1377.py -s
py36 create: /Users/jaraco/Dropbox/code/public/cherrypy/.tox/py36
py36 develop-inst: /Users/jaraco/Dropbox/code/public/cherrypy
py36 installed: You are using pip version 9.0.1, however version 10.0.1 is available.,You should consider upgrading via the 'pip install --upgrade pip' command.,atomicwrites==1.1.5,attrs==18.1.0,backports.functools-lru-cache==1.5,backports.unittest-mock==1.3,certifi==2018.4.16,chardet==3.0.4,cheroot==6.3.1,-e git+gh://cherrypy/cherrypy@86ce228bdb55b4d74b55e70154d4816cdc355a53#egg=CherryPy,codecov==2.0.15,coverage==4.5.1,graphviz==0.8.3,idna==2.6,more-itertools==4.2.0,objgraph==3.4.0,path.py==11.0.1,pluggy==0.6.0,portend==2.2,py==1.5.3,pytest==3.6.0,pytest-cov==2.5.1,pytest-sugar==0.9.1,pytz==2018.4,repoze.lru==0.7,requests==2.18.4,requests-toolbelt==0.8.0,Routes==2.4.1,six==1.11.0,tempora==1.11,termcolor==1.1.0,urllib3==1.22
py36 runtests: PYTHONHASHSEED='3159197583'
py36 runtests: commands[0] | mkdir -p /Users/jaraco/Dropbox/code/public/cherrypy/.test-results/pytest
py36 runtests: commands[1] | pytest test-1377.py -s
Test session starts (platform: darwin, Python 3.6.4, pytest 3.6.0, pytest-sugar 0.9.1)
cachedir: .pytest_cache
rootdir: /Users/jaraco/Dropbox/code/public/cherrypy, inifile: pytest.ini
plugins: sugar-0.9.1, cov-2.5.1, backports.unittest-mock-1.3
[28/May/2018:14:35:57] ENGINE Bus STARTING
[28/May/2018:14:35:57] ENGINE Started monitor thread 'Autoreloader'.
[28/May/2018:14:36:03] ENGINE Error in 'start' listener <bound method Server.start of <cherrypy._cpserver.Server object at 0x10d821630>>
Traceback (most recent call last):
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/process/wspbus.py", line 230, in publish
output.append(listener(*args, **kwargs))
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/_cpserver.py", line 191, in start
super(Server, self).start()
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/process/servers.py", line 184, in start
self.wait()
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/process/servers.py", line 260, in wait
portend.occupied(*self.bound_addr, timeout=Timeouts.occupied)
File "/Users/jaraco/Dropbox/code/public/cherrypy/.tox/py36/lib/python3.6/site-packages/portend.py", line 151, in occupied
raise Timeout("Port {port} not bound on {host}.".format(**locals()))
portend.Timeout: Port 59851 not bound on 127.0.0.1.
[28/May/2018:14:36:03] ENGINE Shutting down due to error in start listener:
Traceback (most recent call last):
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/process/wspbus.py", line 268, in start
self.publish('start')
File "/Users/jaraco/Dropbox/code/public/cherrypy/cherrypy/process/wspbus.py", line 248, in publish
raise exc
cherrypy.process.wspbus.ChannelFailures: Timeout('Port 59851 not bound on 127.0.0.1.',)
[28/May/2018:14:36:03] ENGINE Bus STOPPING
[28/May/2018:14:36:03] ENGINE HTTP Server cherrypy._cpnative_server.CPHTTPServer(('127.0.0.1', 8080)) already shut down
[28/May/2018:14:36:03] ENGINE Stopped thread 'Autoreloader'.
[28/May/2018:14:36:03] ENGINE Bus STOPPED
[28/May/2018:14:36:03] ENGINE Bus EXITING
[28/May/2018:14:36:03] ENGINE Bus EXITED
ERROR: InvocationError for command '/Users/jaraco/Dropbox/code/public/cherrypy/.tox/py36/bin/pytest test-1377.py -s' (exited with code 70)
___________________________________________________________________ summary ____________________________________________________________________
ERROR: py36: commands failed I'm still unsuccessful in setting up a native HTTP server. Any idea what I'm doing wrong in attempting to replicate the reported issue? |
@jaraco try not changing port and sticking to default. I experienced some issues (I didn't find out why) when trying to change port, but it worked (replicated) with default port setting. |
Indeed. That seems like another bug (or limitation, maybe). Working with the default port, the test now replicates the reported failure. Thanks for the tip. |
@jaraco this is still open, but changelog for |
Oh, Cheroot is probably irrelevant.. But some STR would be useful. |
Right, this test fails under Windows: https://github.com/cherrypy/cherrypy/pull/1712/files#diff-38455dfb545934fdb8aaae27bbfd32adR11 |
If I recall correctly, the tests were using Unix sockets, so the tests couldn’t run on Windows. Still, some things were fixed. Probably better to open a new issue at this point for ongoing issues. Link to this one for reference. |
@jaraco, no, those unix socket tests are in cheroot |
hmm. Okay. Reviewing that change, it does seem that I disabled the test without a good reason (other than it was failing and I wanted to get the fix out that was passing on Unix). We should revisit and investigate why it's failing on Windows only and get that fixed too. |
I'm seeing what looking like the same old error on Linux. I'm running Ubuntu 19.04, Python 3.7.3, CherryPy 18.1.1, and cheroot 6.5.5. Here's the output from running the example code and trying to visit
|
@Kodiologist mind submitting a test for this? I think we need to improve bytes/unicode conversion... |
Sure, I'll try it out. |
I wrote this test, but it seems to pass, instead of failing as it ought to. import cherrypy
from cherrypy.test import helper
class Root(object):
@cherrypy.expose
def index(self):
return 'payload'
class T(helper.CPWebCase):
@staticmethod
def setup_server():
from cherrypy._cpnative_server import CPHTTPServer
cherrypy.server.httpserver = CPHTTPServer(cherrypy.server)
cherrypy.tree.mount(root=Root())
def test_cpnative(self):
self.getPage('/')
self.assertStatus('200 OK')
self.assertBody('payload') |
@Kodiologist could you submit that as a PR plz so that we could see whether it'll happen in the CI? |
Apparently, a similar test already exists: https://github.com/cherrypy/cherrypy/pull/1712/files#diff-38455dfb545934fdb8aaae27bbfd32adR33. And it doesn't fail for a mysterious reason. cc @jaraco |
I've submitted a fix here: #1785. |
I've released the fix under v18.1.2 and v17.4.2. |
It looks like this fix breaks server in some circumstances, @webknjaz
Sometimes there will be several of them, sometimes hundreds but at the end application becomes completely unresponsive. No CPU load, no additional memory consumption, nothing new in logs. All requests are just timing out. This was happening sporadically but constantly. Most probably because of some specific combination of request data which, unfortunately, we couldn't recognize. We use Ubuntu 16.04 LTS. |
@MSayfullin looks like that's a Cheroot issue which manifests itself with a combination with a certain version of the OpenSSL. Please create a new issue under Cheroot and fill in all of the required details and include a minimal reproducer if possible. |
@webknjaz thanks for getting back to me. What concerns me also is that according to a history of releases in GitHub cheroot's latest one is dated by January 14 and cherrypy version which works for us (v18.1.1) is released on March 27th. This makes me believe that both versions v18.1.1 and v18.1.2 use the same cheroot version and only change that could affect our app is PR #1785 |
This doesn't look related to that PR at all. Are you sure you used the same Cheroot version in both cases? Do you pin your env deps versions? |
We didn't update or downgrade cheroot version and still use 6.2.4. Hope this helps, @webknjaz |
Well, then my best guess is that you were updating something related to openssl on the OS level maybe. |
That's the thing, only thing updated was cherrypy :) |
Anyway, this needs a real reproducer and a separate issue. The info provided isn't sufficient to conclude any relation to this change. |
I don't think we can realistically roll back this change, but do feel free to open a new bug (preferably with a means to reproduce the issue) to track the regression/degradation. |
Originally reported by: Tim Miller (Bitbucket: lashni, GitHub: Unknown)
http://docs.cherrypy.org/en/latest/advanced.html#no-need-for-the-wsgi-interface
Error is encountered when the example code from the link above is run under a python 3.4.3 virtualenv on archlinux, traceback triggers when the server is accessed. Error doesn't occur with python 2.7.10.
Happens with both current head and CherryPy 3.8.0.
The text was updated successfully, but these errors were encountered: