Quantcast

Re: Delivery Status Notification (Failure)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Delivery Status Notification (Failure)

Mekdelawit Woldegabriel
ello everyone , 
I am a newbie to web application and Cherrypy.i tried the tutorials on the documentation and i couldn't eliminate the error raised at tutorial 9 Data is all my life.The html,CSS works fine .The data base and the table are created properly.But error comes on the generator function.The code is as follows.
import os ,os.path
import random
import sqlite3
import string
import time

import cherrypy

DB_STRING = "C:\SQLite\pythonsqlite2.db"

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


@cherrypy.expose
class StringGeneratorWebService(object):

@cherrypy.tools.accept(media='text/plain')
def GET(self):
with sqlite3.connect(DB_STRING) as c:
cherrypy.session['ts'] = time.time()
r = c.execute("SELECT value FROM user_string WHERE session_id=?",
[cherrypy.session.id])
return r.fetchone()

def POST(self, length=8):
some_string = ''.join(random.sample(string.hexdigits, int(length)))
with sqlite3.connect(DB_STRING) as c:
cherrypy.session['ts'] = time.time()
r = c.execute("INSERT INTO user_string VALUES (?, ?)",
[cherrypy.session.id, some_string])
return some_string

def PUT(self, another_string):
with sqlite3.connect(DB_STRING) as c:
cherrypy.session['ts'] = time.time()
c.execute("UPDATE user_string SET value=? WHERE session_id=?",
[another_string, cherrypy.session.id])

def DELETE(self):
cherrypy.session.pop('ts', None)
with sqlite3.connect(DB_STRING) as c:
c.execute("DELETE FROM user_string WHERE session_id=?",
[cherrypy.session.id])

def setup_database():
"""Create the `user_string` table in the database
on server startup """

with sqlite3.connect(DB_STRING) as con:
con.execute("CREATE TABLE user_string (session_id, value)")

def cleanup_database():

""" Destroy the `user_string` table from the database
on server shutdown.
"""
with sqlite3.connect(DB_STRING) as con:
con.execute("DROP TABLE user_string")

if __name__ == '__main__':

conf = {

'/': {

'tools.sessions.on': True,
'tools.staticdir.root': os.path.abspath(os.getcwd())
},

'/generator': {

'request.dispatch': cherrypy.dispatch.MethodDispatcher(),

'tools.response_headers.on': True,

'tools.response_headers.headers': [('Content-Type', 'text/plain')],
},

'/static': {

'tools.staticdir.on': True,

'tools.staticdir.dir': '.\static'
}
}

cherrypy.engine.subscribe('start', setup_database)

cherrypy.engine.subscribe('stop', cleanup_database)

webapp = StringGenerator()

webapp.generator = StringGeneratorWebService()

cherrypy.quickstart(webapp, '/', conf)

The error is 
 webapp.generator = StringGeneratorWebService()
TypeError: expose_() missing 1 required positional argument: 'func'

please help as soon as possible.

On Thu, Mar 16, 2017 at 5:39 PM, Mail Delivery Subsystem <[hidden email]> wrote:
Hello [hidden email],

We're writing to let you know that the group you tried to contact (cherrypy-users) may not exist, or you may not have permission to post messages to the group. A few more details on why you weren't able to post:

 * You might have spelled or formatted the group name incorrectly.
 * The owner of the group may have removed this group.
 * You may need to join the group before receiving permission to post.
 * This group may not be open to posting.

If you have questions related to this or any other Google Group, visit the Help Center at https://groups.google.com/support/.

Thanks,

Google Groups



----- Original message -----

X-Received: by 10.25.193.213 with SMTP id r204mr1345832lff.24.1489675160283;
        Thu, 16 Mar 2017 07:39:20 -0700 (PDT)
Return-Path: <[hidden email]>
Received: from mail-wr0-x236.google.com (mail-wr0-x236.google.com. [2a00:1450:400c:c0c::236])
        by gmr-mx.google.com with ESMTPS id i76si346684wmh.1.2017.03.16.07.39.20
        for <[hidden email]>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Thu, 16 Mar 2017 07:39:20 -0700 (PDT)
Received-SPF: pass (google.com: domain of [hidden email] designates 2a00:1450:400c:c0c::236 as permitted sender) client-ip=2a00:1450:400c:c0c::236;
Authentication-Results: gmr-mx.google.com;
       dkim=pass header.i=@gmail.com;
       spf=pass (google.com: domain of [hidden email] designates 2a00:1450:400c:c0c::236 as permitted sender) smtp.mailfrom=[hidden email];
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
Received: by mail-wr0-x236.google.com with SMTP id u48so33423953wrc.0
        for <[hidden email]>; Thu, 16 Mar 2017 07:39:20 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:from:date:message-id:subject:to;
        bh=8LD1FUbuKe3gP7eSRIaJRs3mF/XEOcEgq5jLBSnAfvU=;
        b=F7oShwighYLCVDf0x7XNtVpmLgSdGIap4fZcibcNMChAccLUABknbE6aSeSnz7w9zx
         z+5rd8jkeS77UkjS7wKlwI/3iaZuUHXcZt0UZJqUwe/puO6SH8P7QTj5HVLMnYV1GFWe
         xEY2Ql41xxQQyVZM5L75iF554K3XeQG7LR/sWKRkeNEYT/llJudcCwSmaf3hYu4pnrYO
         GfLCBqi5BhJIgKG6mUdinpeLXgwwg6K74tDvjvLfefloli4M0BEmghgHThNcBloH0LoI
         gzyMvfsBCpQQPCBhQ7HPdaTaAGDVnYZkWuNAhhNbL8yF0EmBJB38QHXQ0L/DE3OZ5Qc4
         gsTQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
        bh=8LD1FUbuKe3gP7eSRIaJRs3mF/XEOcEgq5jLBSnAfvU=;
        b=Xp9J61MxyDkIY+LLihBBjGVuO0NgbTKtN0ha+7haxYfz4+Ls9LI0ctoxF1yqYPkTrA
         8mHnYbEfow0TqyQPES1o2JBdOboIVcU4U1fRVmKOTttuKgyrOTSh373S6c+1v7WzbUH4
         wQDUJS/locPlC3/ROj5yJWuLRGttnGMDEVa2H+pubHXubkD/70KkDoK1jsN5aNVdfa8t
         EvQHy8/lgwhw/Ce0nKjgSHRJa7QCirUyamIJOvek+jQWgQG/wx9g2DVe6Ddv4oZE8b9C
         g57tmStiaefcQ23nAGc1715dVZJXmmJmF9ewhOOS1OCPRVEYhoTVdtmRXeAxr0iyEsea
         S5AA==
X-Gm-Message-State: AFeK/H26EfduV8WWSqxJh1qeVgFKDQsisb47hZMcRVZciv19KrMxHuAs/NQJ8IzntGCJYcuYhcB4oRZ9PYIFqg==
X-Received: by 10.223.172.137 with SMTP id o9mr9161320wrc.66.1489675159851;
 Thu, 16 Mar 2017 07:39:19 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.80.166.38 with HTTP; Thu, 16 Mar 2017 07:39:19 -0700 (PDT)
From: Mekdelawit Woldegabriel <[hidden email]>
Date: Thu, 16 Mar 2017 17:39:19 +0300
Message-ID: <CAMBUDOLyD3ARKgE5HH=[hidden email]>
Subject: Help needed on SQLite wih cherrypy
To: [hidden email]
Content-Type: multipart/alternative; boundary=001a11477cb6bbdf65054ada06cd

--001a11477cb6bbdf65054ada06cd
Content-Type: text/plain; charset=UTF-8

hello everyone ,
I am a newbie to web application and Cherrypy.i tried the tutorials on the
documentation and i couldn't eliminate the error raised at tutorial 9 Data
is all my life.The html,CSS works fine .The data base and the table are
created properly.But error comes on the generator function.The code is as
follows.

import os ,os.path
import random
import sqlite3
import string
import time

import cherrypy

DB_STRING = "C:\SQLite\pythonsqlite2.db"

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


@cherrypy.expose
class StringGeneratorWebService(object):

  @cherrypy.tools.accept(media='text/plain')
  def GET(self):
    with sqlite3.connect(DB_STRING) as c:
     cherrypy.session['ts'] = time.time()
     r = c.execute("SELECT value FROM user_string WHERE session_id=?",
             [cherrypy.session.id])
    return r.fetchone()

  def POST(self, length=8):
       some_string = ''.join(random.sample(string.hexdigits, int(length)))
       with sqlite3.connect(DB_STRING) as c:
         cherrypy.session['ts'] = time.time()
         r = c.execute("INSERT INTO user_string VALUES (?, ?)",
                  [cherrypy.session.id, some_string])
       return some_string

  def PUT(self, another_string):
    with sqlite3.connect(DB_STRING) as c:
     cherrypy.session['ts'] = time.time()
     c.execute("UPDATE user_string SET value=? WHERE session_id=?",
                  [another_string, cherrypy.session.id])

  def DELETE(self):
    cherrypy.session.pop('ts', None)
    with sqlite3.connect(DB_STRING) as c:
      c.execute("DELETE FROM user_string WHERE session_id=?",
                [cherrypy.session.id])

def setup_database():
     """Create the `user_string` table in the database
         on server startup """

     with sqlite3.connect(DB_STRING) as con:
      con.execute("CREATE TABLE user_string (session_id, value)")

def cleanup_database():

      """ Destroy the `user_string` table from the database
         on server shutdown.
         """
      with sqlite3.connect(DB_STRING) as con:
            con.execute("DROP TABLE user_string")

if __name__ == '__main__':

            conf = {

            '/': {

            'tools.sessions.on': True,
            'tools.staticdir.root': os.path.abspath(os.getcwd())
            },

            '/generator': {

            'request.dispatch': cherrypy.dispatch.MethodDispatcher(),

            'tools.response_headers.on': True,

            'tools.response_headers.headers': [('Content-Type', 'text/plain')],
            },

            '/static': {

            'tools.staticdir.on': True,

            'tools.staticdir.dir': '.\static'
            }
                }

            cherrypy.engine.subscribe('start', setup_database)

            cherrypy.engine.subscribe('stop', cleanup_database)

            webapp = StringGenerator()

            webapp.generator = StringGeneratorWebService()

            cherrypy.quickstart(webapp, '/', conf)

The error is

 webapp.generator = StringGeneratorWebService()
TypeError: expose_() missing 1 required positional argument: 'func'


please help as soon as possible.

--001a11477cb6bbdf65054ada06cd
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">hello everyone ,=C2=A0<div>I am a newbie to web applicatio=
n and Cherrypy.i tried the tutorials on the documentation and i couldn&#39;=
t eliminate the error raised at tutorial 9 Data is all my life.The html,CSS=
 works fine .The data base and the table are created properly.But error com=
es on the generator function.The code is as follows.</div><div><pre style=
=3D"color:rgb(0,0,0);font-family:&quot;courier new&quot;;font-size:9pt"><sp=
an style=3D"color:rgb(0,0,128);font-weight:bold">import </span>os ,os.path<=
br><span style=3D"color:rgb(0,0,128);font-weight:bold">import </span>random=
<br><span sty
----- Message truncated -----

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Delivery Status Notification (Failure)

Michiel Overtoom
Hi Mekdelawit,

> On 2017-03-17, at 07:23, Mekdelawit Woldegabriel <[hidden email]> wrote:
>
> DB_STRING = "C:\SQLite\pythonsqlite2.db"

If you want to include backslashes in string literals, either escape them ("c:\\SQLite\\data.db") or use raw strings (r"c:\SQLite\data.db").

Greetings,

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Delivery Status Notification (Failure)

Johan Hartzenberg
In reply to this post by Mekdelawit Woldegabriel
[snip]

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


@cherrypy.expose
class StringGeneratorWebService(object):

@cherrypy.tools.accept(media='text/plain')
def GET(self):
with sqlite3.connect(DB_STRING) as c:
cherrypy.session['ts'] = time.time()
r = c.execute("SELECT value FROM user_string WHERE session_id=?",
[<a href="http://cherrypy.session.id/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fcherrypy.session.id%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF_VThC7_xOlAByPFOID4XaIft9hQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fcherrypy.session.id%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF_VThC7_xOlAByPFOID4XaIft9hQ&#39;;return true;">cherrypy.session.id])
return r.fetchone()
[snip]

@expose goes with the route handler function you want to expose, not with the class.  So that looks like a mistake in the example?


--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Delivery Status Notification (Failure)

Joseph S. Tate


On Fri, Mar 17, 2017 at 9:32 AM Johan Hartzenberg <[hidden email]> wrote:
@expose goes with the route handler function you want to expose, not with the class.  So that looks like a mistake in the example?


You can actually expose the whole class, if your python has the class decorator syntax backported to it: https://github.com/cherrypy/cherrypy/issues/1520

To the OP: which version of python are you using? You may need to decorate each method instead of using a class expose decorator, or change from using

@expose
class Foo:
    ....

to 

class Foo:
    ...
Foo.exposed=True

But you may be able to fix this by upgrading your python version.

 

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Loading...