2012-05-15 31 views
7

Tôi có đoạn mã này được chạy hoàn hảo trên localhost nhưng ném lên lỗi mơ hồ này trên game:Lỗi nhập cho tài khoản Mẫu

import_string() failed for 'webapp2_extras.appengine.auth.models.User' . Possible reasons are: - missing __init__.py in a package; - package or module

báo cáo nhập của tôi:

from webapp2_extras import auth 
from webapp2_extras import sessions 
from webapp2_extras.auth import InvalidAuthIdError 
from webapp2_extras.auth import InvalidPasswordError 

Cách sử dụng của auth's mô hình người dùng:

user = self.auth.store.user_model.create_user(username, password_raw = password, email = email) 
if not user[0]: #returns a tuple with [boolean, user_info] 
    return 'Create user error' 
else: 
    self.set_flash("Thank you for registering. Please login!") 
    self.redirect(self.auth_config['login_url']) 

Full code

UPDATE (Full stack trace)

import_string() failed for 'webapp2_extras.appengine.auth.models.User'. Possible reasons are: 

- missing __init__.py in a package; 
- package or module path not included in sys.path; 
- duplicated package or module name taking precedence in sys.path; 
- missing module, class, function or variable; 

Original exception: 

ImportError: No module named ndb 

Debugged import: 

- 'webapp2_extras' found in '/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2_extras/__init__.pyc'. 
- 'webapp2_extras.appengine' found in '/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2_extras/appengine/__init__.pyc'. 
- 'webapp2_extras.appengine.auth' found in '/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2_extras/appengine/auth/__init__.pyc'. 
- 'webapp2_extras.appengine.auth.models' not found. 
Traceback (most recent call last): 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__ 
    rv = self.handle_exception(request, response, e) 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__ 
    rv = self.router.dispatch(request, response) 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher 
    return route.handler_adapter(request, response) 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__ 
    return handler.dispatch() 
    File "/base/data/home/apps/s~webapp-auth/1.358936463581927371/main.py", line 34, in dispatch 
    response = super(BaseHandler, self).dispatch() 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch 
    return self.handle_exception(e, self.app.debug) 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch 
    return method(*args, **kwargs) 
    File "/base/data/home/apps/s~webapp-auth/1.358936463581927371/main.py", line 127, in post 
    user = self.auth.store.user_model.create_user(username, password_raw = password, email = email) 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 701, in __get__ 
    value = self.func(obj) 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2_extras/auth.py", line 131, in user_model 
    cls = self.config['user_model'] = webapp2.import_string(cls) 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1824, in import_string 
    return getattr(__import__(module, None, None, [obj]), obj) 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2_extras/appengine/auth/models.py", line 13, in <module> 
    from ndb import model 
+0

Bạn có thể đăng một lần truy nguyên đầy đủ không. –

Trả lời

12

Nhìn tương tự như issue này mà đã được cố định bởi webapp 2.5.1

Hãy chắc chắn rằng bạn nhập các phiên bản mới nhất của webapp2, bằng cách thêm những dòng vào tệp app.yaml của bạn:

libraries: 
- name: webapp2 
    version: latest 

Giải pháp thay thế bạn có thể thêm các dòng sau vào ứng dụng của mình:

import sys 
from google.appengine.ext import ndb 
sys.modules['ndb'] = ndb 
+0

Điều này hoạt động giống như một sự quyến rũ. Bạn thật tuyệt vời. Cảm ơn bạn rất nhiều xD – Prakhar

+4

Lưu ý rằng 'phiên bản: mới nhất' phải được sử dụng w/thận trọng, vì nó sẽ tự động cập nhật lên phiên bản mới nhất của webapp. 'phiên bản: 2.5.1' sẽ an toàn hơn. – proppy

Các vấn đề liên quan