Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cherrypy - no response to requests
#1
Hello.
I have problem with deploying cherrypy on Centos7.
I've worked with cherrypy on Windows (json, postgresql etc.) for few years now without any problems and I don't uderstand what I do wrong in case of Centos.

My "obervations" so far:
- Cherrypy is installed as Python3 package
- There is no any issues with Python3 scripts
- SSH, sFTP work without any issues
- Apache operates on ports like 80, 6060, 9090 without any issues
- iptables and firewalld turned off
- no other software is listening to port 2020
- cherrypy starts without syntax error notifications
- no cherrypy processes duplicated
- 'localhost' and '127.0.0.1' are resolved properly



Sample cherrypy script:

import cherrypy

class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        return "Hello World!"

cherrypy.config.update({'Access-Control-Allow-Origin': 'http://127.0.0.1',
    'server.socket_host': '127.0.0.1', 'server.socket_port': 2020})

cherrypy.quickstart(HelloWorld())
The problem is that I can't receive any response to a request.


command:
netstat -tulpn | grep :2020
output:
LISTEN 5239/python3 (PID is correct - this is process started by cherrypy)



command:
wget http://127.0.0.1:2020
output:
Connecting to 127.0.0.1:2020... connected.
HTTP request sent, awaiting response...


- the same effect if I use Python3 'requests' module (no response from cherrypy)
- unfortunately cherrypy wasn't able to write down any logs during requests

Could somebody with more experience with centos please point me in the right direction, because I have no idea where to go next / what to check.

Regards.
Reply
#2
The problem is definitely OS/environment specific. I just ran your code and it worked fine (OpenSuse 42.3).

Could you run a simple http server,

Output:
python -m http.server 2020 --bind 127.0.0.1
and make a request to it, using e.g. wget?
Reply
#3
Thank you for your answer.


1.
I killed cherrypy process

2.
command:
python3 -m http.server 2020 --bind 127.0.0.1
output:
Serving HTTP on 127.0.0.1 port 2020 (http://127.0.0.1:2020/) ...

3.
command:
ps aux
output:
13487 0.1 0.4 91588 14432 pts/0 T 08:44 0:00 python3 -m http.server 2020 --bind 127.0.0.1

4.
command:
netstat -tulpn | grep :2020
output:
tcp 1 0 127.0.0.1:2020 0.0.0.0:* LISTEN 13487/python3

5.
command:
wget http://127.0.0.1:2020
output:
Connecting to 127.0.0.1:2020... connected.
HTTP request sent, awaiting response...


The same answer as with cherrypy. What does it mean?


PS: I also disabled SElinux
Reply
#4
I'm working on some cgi listen server projects if I enter your console commands in a new tab I get totally different responses. I believe there's a problem with your http server here's my server code:
#cgi_webserver.py
import os, sys
from http.server import HTTPServer, CGIHTTPRequestHandler

webdir= '.'
port= 80

os.chdir(webdir)
srvraddr= ("", port)

srvrobj= HTTPServer(srvraddr, CGIHTTPRequestHandler)
srvrobj.serve_forever()
in linux terminal: sudo python3 cgi_webserver.py
Reply
#5
Something wrong with network/firewall configuration?! The problem isn't in cherrypy.
Reply
#6
post your output after you start your script there may be information
here's mine for your script:
Output:
[15/May/2019:09:02:21] ENGINE Listening for SIGUSR1. [15/May/2019:09:02:21] ENGINE Listening for SIGTERM. [15/May/2019:09:02:21] ENGINE Listening for SIGHUP. [15/May/2019:09:02:21] ENGINE Bus STARTING Warning (from warnings module): File "/home/pi/.local/lib/python3.5/site-packages/cherrypy/_cpchecker.py", line 105 warnings.warn(msg) UserWarning: The Application mounted at '' has an empty config. [15/May/2019:09:02:21] ENGINE Started monitor thread 'Autoreloader'. [15/May/2019:09:02:21] ENGINE Serving on http://127.0.0.1:2020 [15/May/2019:09:02:21] ENGINE Bus STARTED
Reply
#7
Thank you for the advices . I asked the same question on Centos forum and some of the administrators answered me that in his opinion there is everything fine with operating system, it’s just that it has nothing to respond with. All your advices and the answer from Centos forum pointed me in the right direction.
It found out that the problem was that cherrypy server wasn’t active at all, because of the wrong initiation method. It should be started in background and not as usual Python script (otherwise it stops working every time system administrator goes back to prompt shell).
So in fact cherrypy server wasn’t working even though its process was visible and it was operating on the right port.



Here is the solution:

instead of this command:

python3 cherrypy_script.py

should be this one:

nohub python3 cherrypy_script.py &

(cherrypy run in background)
(all output, including any error messages, are written to the file nohup.out in the working directory, or in home directory)
(‘&’ means: ‘go back to shell prompt’)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  POST requests - different requests return the same response Default_001 3 1,901 Mar-10-2022, 11:26 PM
Last Post: Default_001

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020