小编Oha*_*rry的帖子

flask request args parser error 浏览器(或代理)发送了一个此服务器无法理解的请求

使用 test_client 并发送如下请求:

app = Flask(__name__)
client = app.test_client()

headers = {'content-type': 'application/json', 'Authorization': u'Bearer fake_token_123'}
params = {'dont_care': True}
client.get(??'/my_route/123', query_string=params, headers=headers)
Run Code Online (Sandbox Code Playgroud)

我的路线是

class MyController(Resource):

    def get(self, id):
        parser = reqparse.RequestParser()
        parser.add_argument('currency', type=str, default='USD', help="help text")

        args = parser.parse_args()
        currency_from_params = args.currency
Run Code Online (Sandbox Code Playgroud)

parser.parse_args() 失败

The browser (or proxy) sent a request that this server could not understand
Run Code Online (Sandbox Code Playgroud)

'content-type': 'application/json'从标题中删除时,它可以工作

我不明白这种行为,如果没有 un优雅的try, expect.

谢谢你的帮助

python flask flask-restful

5
推荐指数
1
解决办法
2792
查看次数

如何使用pyenv安装的python创建virtualenv

我安装了2个pyenv版本

pyenv versions
  system
* 2.7 (set by ../.python-version)
  3.5.3
Run Code Online (Sandbox Code Playgroud)

当我virtualenv在项目目录中创建一个内部目录时,我希望它virtualenv为当前的pyenvpython版本创建一个2.7

但是当我使用创建一个 mkvirtualenv whatever

虚拟环境正在创建python3 virtualenv

ll ~/.virtualenvs/mobile2/bin
total 5800
-rw-r--r--  1 ohadperry  staff   2.0K Sep  6 10:59 activate
-rw-r--r--  1 ohadperry  staff   1.0K Sep  6 10:59 activate.csh
-rw-r--r--  1 ohadperry  staff   2.1K Sep  6 10:59 activate.fish
-rw-r--r--  1 ohadperry  staff   1.1K Sep  6 10:59 activate_this.py
-rwxr-xr-x  1 ohadperry  staff   266B Sep  6 10:59 easy_install
-rwxr-xr-x  1 ohadperry  staff   266B Sep  6 10:59 …
Run Code Online (Sandbox Code Playgroud)

python virtualenv virtualenvwrapper pyenv

2
推荐指数
1
解决办法
553
查看次数