title: Reading input from an HTML form in CherryPy
body: <p>I am looking to read a value from an HTML form into a CherryPy endpoint:</p>
  <pre><code>class MyWebService(object):
  
      def generate_random_string(length = 6):
          letters = string.ascii_lowercase
          print(&quot;length: &quot; + str(length))
          result_str = ''.join(random.sample(letters, k = length))
          print(&quot;Random String is:&quot;, result_str)
          return result_str
  
      @cherrypy.expose
      def index(self):
          return &quot;&quot;&quot;&lt;form method=&quot;POST&quot; action=&quot;randomize&quot;&gt;
            &lt;input type=&quot;text&quot; name=&quot;the_link&quot; size=&quot;50&quot;/&gt;
            &lt;button type=&quot;submit&quot;&gt;Randomize!&lt;/button&gt;
          &lt;/form&gt;&quot;&quot;&quot;
  
      @cherrypy.expose
      def randomize(self, the_link):
          random_string = self.generate_random_string()
          log_statement = link + &quot; converted to: &quot; + random_string
          return log_statement
  
  if __name__ == '__main__':
      config = {'server.socket_host': '0.0.0.0'}
      cherrypy.config.update(config)
      cherrypy.quickstart(MyWebService())
      cherrypy.quickstart(MyWebService(), '/', config)
  </code></pre>
  <p>When I run the code and go to <code>localhost:8080</code> and type in a value for <code>the_link</code>, I see this error:</p>
  <pre><code>File &quot;app.py&quot;, line 25, in generate_random_string
      result_str = ''.join(random.sample(letters, k = length))
    File &quot;/opt/anaconda3/lib/python3.8/random.py&quot;, line 362, in sample
      if not 0 &lt;= k &lt;= n:
  TypeError: '&lt;=' not supported between instances of 'int' and 'MyWebService'File &quot;app.py&quot;, line 25, in generate_random_string
      result_str = ''.join(random.sample(letters, k = length))
    File &quot;/opt/anaconda3/lib/python3.8/random.py&quot;, line 362, in sample
      if not 0 &lt;= k &lt;= n:
  TypeError: '&lt;=' not supported between instances of 'int' and 'MyWebService'
  </code></pre>
  <p>I do not understand why <code>n</code> is of type <code>MyWebService</code>. Can you point out why? The <code>generate_random_string()</code> function works as expected outside of this source file.</p>