所以我正在尝试使用Flask-Restless。不幸的是我无法导入flask.ext.restless。
>>> from flask.ext.restless import APIManager
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
File "/Users/mrkaiser/.virtualenvs/dcenv/lib/python3.3/site-packages/flask/exthook.py", line 62, in load_module
__import__(realname)
File "/Users/mrkaiser/.virtualenvs/dcenv/lib/python3.3/site-packages/flask_restless/__init__.py", line 22, in <module>
from .manager import APIManager
File "/Users/mrkaiser/.virtualenvs/dcenv/lib/python3.3/site-packages/flask_restless/manager.py", line 17, in <module>
from .views import API
File "/Users/mrkaiser/.virtualenvs/dcenv/lib/python3.3/site-packages/flask_restless/views.py", line 114
except ProcessingException, exception:
>>> import flask.ext.restless
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
File "/Users/mrkaiser/.virtualenvs/dcenv/lib/python3.3/site-packages/flask/exthook.py", line 62, in load_module
__import__(realname)
File "/Users/mrkaiser/.virtualenvs/dcenv/lib/python3.3/site-packages/flask_restless/__init__.py", line 22, in <module>
from .manager import APIManager
File "/Users/mrkaiser/.virtualenvs/dcenv/lib/python3.3/site-packages/flask_restless/manager.py", line 17, in <module>
from .views import API
File "/Users/mrkaiser/.virtualenvs/dcenv/lib/python3.3/site-packages/flask_restless/views.py", line 114
except ProcessingException, exception:
^
SyntaxError: invalid syntax
这些是我当前virtualenv中的软件包。
$ pip freeze
Flask==0.10.1
Flask-Admin==1.0.7
Flask-Restless==0.12.1
Flask-SQLAlchemy==1.0
Jinja2==2.7.2
MarkupSafe==0.18
SQLAlchemy==0.9.2
WTForms==1.0.5
Werkzeug==0.9.4
itsdangerous==0.23
mysql-connector-python==1.1.5
python-dateutil==2.2
six==1.5.2
我一直在尝试做这个教程(虽然稍作修改): 作者 ='mrkaiser'
import flask
from sqlalchemy import Column, Integer, String, Sequence
from sqlalchemy import ForeignKey
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import backref, relationship
from sqlalchemy.orm import scoped_session, sessionmaker
from flask.ext.restless import APIManager
app = Flask(__name__)
engine = create_engine('mysql+mysqlconnector://flask:dummypass@localhost/test', convert_unicode=True)
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
mysession = scoped_session(Session)
Base = declarative_base()
Base.metadata.bind = engine
class Person(Base):
__tablename__ = 'people'
id = Column(Integer, Sequence('person_id_seq'), primary_key=True)
first_name = Column(String(50))
last_name = Column(String(50))
url = Column(String(150))
about = Column(String(400))
def __repr__(self):
return "Person<first_name=%s,last_name=%s,url=%s" % (self. first_name, self.last_name, self.url)
# Create the database tables.
Base.metadata.create_all()
# Create the Flask-Restless API manager.
manager = flask.ext.restless.APIManager(app, session=mysession)
# Create API endpoints, which will be available at /api/<tablename> by
# default. Allowed HTTP methods can be specified as well.
manager.create_api(Person, methods=['GET'])
# start the flask loop
app.run()
我通过命令行运行时遇到同样的错误。不知道该怎么办。谢谢!
答案 0 :(得分:1)
对于那些在python 3中有不同问题的人,请升级到current dev version。问题已修复here。
pip install git+https://github.com/jfinkels/flask-restless/