Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 27 13:35
    rkachach opened #1963
  • May 23 17:53
    pre-commit-ci[bot] synchronize #1950
  • May 23 17:53
    pre-commit-ci[bot] edited #1950
  • May 23 17:53

    pre-commit-ci[bot] on pre-commit-ci-update-config

    [pre-commit.ci] pre-commit auto… (compare)

  • May 19 21:10
    sanderjo commented #1962
  • May 19 20:53
    sanderjo closed #1962
  • May 19 20:53
    sanderjo commented #1962
  • May 19 20:26
    sanderjo opened #1962
  • May 16 18:43
    pre-commit-ci[bot] synchronize #1950
  • May 16 18:43
    pre-commit-ci[bot] edited #1950
  • May 16 18:43

    pre-commit-ci[bot] on pre-commit-ci-update-config

    [pre-commit.ci] pre-commit auto… (compare)

  • May 12 22:57
    timboe51 closed #1961
  • May 12 22:32
    timboe51 edited #1961
  • May 12 22:28
    timboe51 opened #1961
  • May 12 22:08
    timboe51 closed #1960
  • May 11 22:29
    timboe51 opened #1960
  • May 09 11:11
    Safihre commented #1945
  • Apr 18 12:59
    jiangwen365 synchronize #1957
  • Apr 17 22:25
    webknjaz commented #1833
  • Apr 16 14:35
    pre-commit-ci[bot] synchronize #1957
Sviatoslav Sydorenko
@webknjaz
print where?
console?
CherryPy is an HTTP framework so the expected use is to send data in HTTP responses
tithir
@tithir
@webknjaz print the same in the front end
this is the code

import cherrypy
import os
import os.path

class PreecoolingDC(object):
@cherrypy.expose
def index(self):
return open('index.html')

@cherrypy.expose
def store(self,length=30):
    exc = exec(open('file.py').read())
    return "Hello %s" % exc                  

configfile = os.path.join(os.path.dirname(file),'server.conf')
cherrypy.quickstart(PreecoolingDC(),config=configfile)

Sviatoslav Sydorenko
@webknjaz
Well, this does send the HTTP response just fine (ignoring the fact that exec() is evil and must almost never be used)
tithir
@tithir
How should that be used if you can help with an example
Sviatoslav Sydorenko
@webknjaz
That is up to you
for example,
$ curl http://localhost:8080/store
Alexandre LICINIO
@alexandre.licinio_gitlab
you can also use mako to display from server to a webpage
from mako.lookup import TemplateLookup

@cherrypy.expose
    def index(self):
            template = lookup.get_template("index.html")
            return template.render(foo='bar')
in your html
<title>${foo}</title>
Rainy Kala
@rainy_kala:matrix.org
[m]
Hi All,
Any suggestions for below error:
CherryPy ERROR cherrypy.error LN: 216 ENGINE Error in 'start' listener <bound method Server.start of <cherrypy._cpserver.Server object at 0x7f17e6264470>>
Traceback (most recent call last):
File "cherrypy/process/wspbus.py", line 230, in publish
File "cherrypy/_cpserver.py", line 180, in start
File "cherrypy/process/servers.py", line 177, in start
File "portend.py", line 122, in free
File "portend.py", line 71, in assert_free
File "portend.py", line 74, in _connect
File "socket.py", line 144, in init
OSError: [Errno 97] Address family not supported by protocol
CherryPy ERROR cherrypy.error LN: 216 ENGINE Shutting down due to error in start listener:
Traceback (most recent call last):
File "cherrypy/process/wspbus.py", line 268, in start
File "cherrypy/process/wspbus.py", line 248, in publish
cherrypy.process.wspbus.ChannelFailures: OSError(97, 'Address family not supported by protocol')
Sviatoslav Sydorenko
@webknjaz
Looks like you specified something weird to listen to
Rainy Kala
@rainy_kala:matrix.org
[m]
The above code is running inside a docker container, and which is running on jenkins pipeline on ubuntu machine. Let me know, if any other details required.
Jason R. Coombs
@jaraco
@rainy_kala:matrix.org You’ll want to investigate the code you use to start the server and in particular look at any bind parameters. I recommend trying to deploy a hello world and see if that works and then add in the server settings from your application until the error occurs. Good luck.
Gildas Bayard
@wizen_gitlab
Hello. Is it normal if https://docs.cherrypy.org website is down for a few days?
Sviatoslav Sydorenko
@webknjaz
Damascene
@uak_gitlab
Hi, is it safe to allow the ssl certificate pem files to be read by cherrypy user? any alternative for that?
Jason R. Coombs
@jaraco
@uak_gitlab I’m unsure what you mean. Do you mean the user that’s running the cherrypy web server process? I’d say that you don’t want to expose any certificate keys except to users that need them. So, if your pem files contain the encryption keys and you are using CherryPy’s built-in SSL, then you must make those files readable by the user under which the web server runs. If the pem files don’t contain any keys, then they contain public information and it’s not important to protect it. If you’re not using CherryPy’s built-in SSL, then you don’t need to provide access to that file at all. Does that help?
Damascene
@uak_gitlab
@jaraco thank you, yeah I was able to setup ssl probably I guess.
I'm having another issue my index() function is called twice when I visit the page. issue is that I put a random number captcha but numbers keep changing
Damascene
@uak_gitlab
how I can post my code?
Here is what I see in logs. the first a = 7 and b = 8 is what is shown on the web but it's not accepted when entered in captcha as it have changed.
a 7
b 8
sum 15
index is called
11.22.333.444 - - [30/Aug/2021:14:51:40] "GET / HTTP/1.1" 200 1210 "" "Mozilla *******"
2021-08-30 14:51:40,209 - cherrypy.access.140525486051232 - INFO - 11.22.333.444 - - [30/Aug/2021:14:51:40] "GET / HTTP/1.1" 200 1210 "" "Mozilla *******"
a 2
b 6
sum 8
index is called
11.22.333.444 - - [30/Aug/2021:14:51:43] "GET / HTTP/1.1" 200 1210 "" "Mozilla *******"
2021-08-30 14:51:43,210 - cherrypy.access.140525486051232 - INFO - 11.22.333.444 - - [30/Aug/2021:14:51:43] "GET / HTTP/1.1" 200 1210 "" "Mozilla *******"
Sviatoslav Sydorenko
@webknjaz
You can post code the same way, using Markdown in this chat, or post it at https://gist.new.
Marcos
@IngMarcosLopez
Hey guys !!
does any of you have ever deployed a cherrypy app in Heroku?
any tip or example to deploy complex apps?
Sviatoslav Sydorenko
@webknjaz
this question is too vague, try to ask more concrete question with examples
Damascene
@uak_gitlab
I've a pure cherrypy website running on https. http links to it not working. Is it possible to have request forward from http to https without enabling server on both ports?
Damascene
@uak_gitlab
if no, how to make http request forward to the other server. I'm running now two different cherrypy instances one with http directing to the https one
Sviatoslav Sydorenko
@webknjaz
You'll need to listen to both ports.
I guess you could have a tool inspecting the requests and performing redirects — https://docs.cherrypy.dev/en/latest/extend.html#per-request-functions
Damascene
@uak_gitlab
Thanks I'll check how to use that
Damascene
@uak_gitlab
class Functions():
    def check_ssl(self=None):
        # check if url is in https and redirect if http
        if cherrypy.request.scheme == "http":
            cherrypy.HTTPRedirect(Referer.replace("http:", "https:"))

    cherrypy.tools.Functions = cherrypy.Tool('before_handler', check_ssl)

this doesn't seem to be working with recent version, I'm getting this error:

[04/Oct/2021:09:31:44]  
Traceback (most recent call last):
  File "/home/userhome/cherry/venv/lib/python3.8/site-packages/cherrypy/_cprequest.py", line 117, in run_hooks
    hook()
  File "/home/userhome/cherry/venv/lib/python3.8/site-packages/cherrypy/_cprequest.py", line 65, in __call__
    return self.callback(**self.kwargs)
  File "cherry_generate.py", line 10, in check_ssl
    cherrypy.HTTPRedirect(Referer.replace("http:", "https:"))
NameError: name 'Referer' is not defined

https://stackoverflow.com/questions/14674973/warning-when-http-used-instead-of-https

3 replies
Damascene
@uak_gitlab

Here is my setup for cherrypy, I wanted to share it with community. Would like to hear your suggestions for improvements:
Using 443 port, dropping privileges, favicon, storing data in session and custom captcha

https://gitlab.com/uak/light-crypto-faucet/-/blob/main/faucet-web/web_faucet.py

dylanetaft
@dylanetaft
How dangerous is this? Lol. I want to do JSON-RPC with Cherrypy without a stupid third party lib. https://pastebin.com/dfgM5XM4 It's like 8 lines of code.
dylanetaft
@dylanetaft
Nevermind, I'll use a dictionary and dictionary.get, and maintain a mapping of API names to internal functions.
That is so much cleaner lol
Marcos
@IngMarcosLopez
image.png
1 reply
Hi all !!
Does anyone knows how to solve this error ?
I have this conf on the server:
"server.ssl_certificate": 'cert.crt',
"server.ssl_private_key": 'server.key''
On the browser doesn't display any error at page load
Jason R. Coombs
@jaraco
@IngMarcosLopez I don’t know how to solve that. Probably there’s some error in the terminal where the cherrypy server is running. If not, then you’re probably not reaching the server. I personally don’t use SSL within cherrypy and instead put an HTTP engine in front of it (Nginx, IIS). For an example of how I do that, look at https://github.com/jaraco/jaraco.site. The nginx config is in the ‘ubuntu’ folder. The fabfile.py shows how the site is configured/installed.
1 reply
greentip
@greentip:matrix.org
[m]
Hello, I setup log rotate to rotate the logs but I see the log file is not being used after rotation. Is there a way to have logrotate replace the log file without cherrypy stop logging?
Sviatoslav Sydorenko
@webknjaz
It's hard to answer given that there's no details of how you configured your app. Did you follow https://docs.cherrypy.dev/en/latest/basics.html#play-along-with-your-other-loggers?
If you have a reproducer and think it's a bug, file an issue on GitHub.
greentip
@greentip:matrix.org
[m]
hi which one will take precedent, the config.update or the configurations in the configuration file? should I remove the entry in configuration file for the explicit one to work?
if __name__ == '__main__':
    cherrypy.config.update({
        'tools.proxy.on': True,
    })

    cherrypy.quickstart(Form(),config=cherrypy.conf)
1 reply
greentip
@greentip:matrix.org
[m]
seems the update value are the active one.
greentip
@greentip:matrix.org
[m]
seems like I'm getting mixed results
greentip
@greentip:matrix.org
[m]
thank you, per-route you mean the one inside cherrypy.quickstart, right?
1 reply