gpt4 book ai didi

python - "where"请求 Eve 中的无效字符 (&)

转载 作者:太空宇宙 更新时间:2023-11-04 10:36:14 24 4
gpt4 key购买 nike

我在我的开发系统中发现了这个问题,并在发现的 Eve 演示中重现了它 here

这是我运行的代码。

    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”,一切运行良好然后我将 with set 设置为“max & me”,然后 eve 吐了我一身:

    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

可能是我没有处理 <&> 符号 - 但我觉得我已经尝试了各种编码......而且我卡住了......每次都是

最佳答案

尝试将 & 替换为其转义版本:%26。我刚刚尝试使用这个 GET 获取 Eve 支持的 API

?where={"name": "你 %26 我"}

它工作得很好。

关于python - "where"请求 Eve 中的无效字符 (&),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23241820/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com