Python Forum
Help resolving error with webpy app
Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help resolving error with webpy app
#1
I'm trying to follow an online course and while the course content and tutorials are generally good, it's absolutely infuriating to follow because the instructor did not post the source code and for reasons unknown, disabled the discussion section of the course. I keep going over and over and over the code but I cannot find where mine is different. I am getting the error below attempting to create a login screen for a simple web app.

Traceback (most recent call last):
 File "/usr/local/lib/python3.6/site-packages/web.py-0.40.dev0-py3.6.egg/web/application.py", line 257, in process
   return self.handle()
 File "/usr/local/lib/python3.6/site-packages/web.py-0.40.dev0-py3.6.egg/web/application.py", line 247, in handle
   fn, args = self._match(self.mapping, web.ctx.path)
 File "/usr/local/lib/python3.6/site-packages/web.py-0.40.dev0-py3.6.egg/web/application.py", line 495, in _match
   for pat, what in mapping:
ValueError: not enough values to unpack (expected 2, got 1)
I suppose that the problem is that I am not sending both the username and password but just one or the other but I'm just speculating here.  Application.py is not part of my program, it's part of the "framework" or whatever you call it.   I am not sure where to even check my code but I will try to post the stuff that seems the most relevant.

import pymongo, bcrypt
from pymongo import MongoClient

class LoginModel:
  def __init__(self):
      self.client = MongoClient()
      self.db = self.client.codewizard
      self.Users = self.db.users

  def check_user(self, data):
      user = self.Users.find_one({"username": data.username})

      if user:
          if bcrypt.checkpw(data.password.encode(), user["password"]):
             return user
          else:
              return False

      else:
          return False
class CheckLogin:
      def POST(self):
          data = web.input()
          login = LoginModel.LoginModel()
          isCorrect = login.check_user(data)

          if isCorrect:
              return isCorrect

          return "error"
<div class="container">

  <h2>Login</h2>
  <br /><br />

  <form id="login-form">
      <div class="form-group label-static is-empty">
          <label for="username" class="control-label">Username</label>
          <input id="username" name="username" class="form-control" type="text" placeholder="Username" />
      </div>
              <div class="form-group label-static is-empty">
          <label for="password" class="control-label">Password</label>
          <input id="password" name="password" class="form-control" type="Password" placeholder="Password" />
      </div>

      <button class="btn btn-raised btn-info waves-effect">Login</button>

  </form>
</div>
$(document).on('submit', '#login-form', function(e){
 e.preventDefault();

 var form = $(this).serialize();
 $.ajax({
     url: '/check-login',
     type: 'POST',
     data: form,
     success: function(res){
         if (res == "error"){
             alert("Could not log in.");
          }else{
             console.log("Logged in as", res);
          }
     }
 })
});
Can anyone help?
Reply
#2
urls = (
   '/', 'Home',
   '/register', 'Register',
   '/login', 'Login',
   '/postregistration', 'PostRegistration',
   '/check-login', 'CheckLogin'
)
Solved.  It was missing a coma (,) after 'PostRegistration'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Resolving ImportError: No module named gdb (Python in C++) mandaxyz 3 1,312 Oct-04-2023, 02:43 PM
Last Post: mandaxyz
  mySQL Database error not resolving. cybertooth 2 3,114 Aug-30-2021, 05:45 PM
Last Post: ibreeden
  resolving issues with path aster 5 4,870 Apr-01-2019, 09:54 AM
Last Post: snippsat
  pathlib: resolving a path that does not exist Skaperen 6 5,386 Sep-08-2018, 12:25 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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