Flask restful

时间:2018-01-16 09:46:09

标签: python rest flask flask-restful

我创建了一个虚拟环境

conda create -p my_env python=3.5

然后我激活了它

activate %cd%\my_env

我安装了一些软件包,其中包括flask_restful

conda install -c anaconda numpyhttps://anaconda.org/anaconda/numpy

conda install -c anaconda pandashttps://anaconda.org/anaconda/pandas

conda install -c conda-forge timehttps://anaconda.org/conda-forge/time

conda install -c anaconda flaskhttps://anaconda.org/anaconda/flask

conda install -c anaconda flask-wtfhttps://anaconda.org/anaconda/flask-wtf

conda install -c conda-forge cassandra-driverhttps://anaconda.org/conda-forge/cassandra-driver

conda instal -c conda-forge flask-restfulhttps://anaconda.org/conda-forge/flask-restful

然后我只是尝试制作一个烧瓶web api。但是,当我写(甚至在空脚本中)

from flask_restful import Resource, Api

我总是得到同样的错误:

Traceback (most recent call last):
  File "C:\Users\Me\Desktop\Myfolders\my_env\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Users\Me\Desktop\Myfolders\run.py", line 3, in <module>
    from flask_restful import Api
  File "C:\Users\Me\Desktop\Myfolders\my_env\lib\site-packages\flask_restful\__init__.py", line 21, in <module>
    import config
ImportError: No module named 'config'

所以我去看看上面目录中的实际脚本__init__.py,确实导入了config,但是,在文件夹“flask_restful”中没有名为config的文件,它似乎也没有在任何其他脚本中导入。

directory

有什么问题?

编辑 - 有关__init __。py

的更多详细信息

这是我所拥有的脚本__init__.py的第一行:

from __future__ import absolute_import
import difflib
from functools import wraps, partial
import re
from flask import request, url_for, current_app
from flask import abort as original_flask_abort
from flask import make_response as original_flask_make_response
from flask.views import MethodView
from flask.signals import got_request_exception
from werkzeug.datastructures import Headers
from werkzeug.exceptions import HTTPException, MethodNotAllowed, NotFound, NotAcceptable, InternalServerError
from werkzeug.http import HTTP_STATUS_CODES
from werkzeug.wrappers import Response as ResponseBase
from flask_restful.utils import http_status_message, unpack, OrderedDict
from flask_restful.representations.json import output_json
import sys
from flask.helpers import _endpoint_from_view_func
from types import MethodType
import operator
from collections import Mapping
import config


__all__ = ('Api', 'Resource', 'marshal', 'marshal_with', 'marshal_with_field', 'abort')


def abort(http_status_code, **kwargs):
    """Raise a HTTPException for the given http_status_code. Attach any keyword
    arguments to the exception for later processing.
    """
    #noinspection PyUnresolvedReferences
    try:
        original_flask_abort(http_status_code)
    except HTTPException as e:
        if len(kwargs):
            e.data = kwargs
        raise

DEFAULT_REPRESENTATIONS = [('application/json', output_json)]

我应该删除它吗?它不在脚本中使用。

编辑2:版本为flask-restful

我不知道如何包含我的flask-restful版本,但是,如果我打开脚本__version__.py,我会找到以下代码:

#!/usr/bin/env python

__version__ = '0.3.6'

0 个答案:

没有答案