1

私の開発システムでこの問題を発見し、 ここにある Eve デモで再現しました。

これは私が実行するコードです。

    import requests
    import json
    import string
    import random
    def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
        return ''.join(random.choice(chars) for _ in range(size))

    name = "max and me"
    data = {"lastname":id_generator(), "firstname":name}

    print data
    res = requests.post("http://127.0.0.1:5000/people", data = data)
    print res.text

    data = 'where={"firstname":"%s"}' % (name)
    res = requests.get("http://127.0.0.1:5000/people", params = data)
    print res.text

まず、変数を含む POST を作成し、同じ変数の where を使用して GET を実行します。最初に、変数を「max and me」に設定すると、すべて正常に実行されます。次に、「max & me」に設定して実行すると、イブが全身に吐き出します。

    127.0.0.1 - - [23/Apr/2014 20:22:07] "GET /people?where=%7B%22firstname%22:%22max%20&%20me%22%7D HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/eve/endpoints.py", line 53, in collections_endpoint
    response = get(resource, lookup)
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/eve/methods/common.py", line 226, in rate_limited
    return f(*args, **kwargs)
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/eve/auth.py", line 45, in decorated
    return f(*args, **kwargs)
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/eve/methods/common.py", line 429, in decorated
    r = f(*args, **kwargs)
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/eve/methods/get.py", line 104, in get
    cursor = app.data.find(resource, req, lookup)
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/eve/io/mongo/mongo.py", line 145, in find
    spec = parse(req.where)
  File "/Users/hingem/Documents/python/venv/lib/python2.7/site-packages/eve/io/mongo/parser.py", line 26, in parse
    v.visit(ast.parse(expression))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ast.py", line 37, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 1
    {"firstname":"max
                     ^
SyntaxError: EOL while scanning string literal

おそらく <&> 記号を処理していないのはおそらく私です-しかし、私はあらゆる種類のエンコーディングを試したと感じています...そして、私は立ち往生しています....毎回

4

2 に答える 2

3

&エスケープされたバージョンに置き換えてみてください: %26。この GET を Eve を利用した API に試してみました

?where={"name": "You %26 me"}

そしてそれはうまくいきました。

于 2014-04-23T14:13:13.093 に答える