Python-夏娃 : query to ip address saved like string

标签 python mongodb eve

我有这个架构:

DOMAIN = {
    'banned': {
        'schema': {
            'ip': {
                'type': 'string',
                'regex': '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$',
                'unique': True,
                'required': True
            },
            'host': {
                'type': 'string'
            },
            'country': {
                'type': 'string'
            },
            'jail': {
                'type': 'string'
            }
        }
    }
}

但是当我尝试使用 curl 进行查询时,如下所示:

curl -i http://localhost:5000/banned?where=ip=='8.8.8.8'

我收到此错误:

HTTP/1.0 400 BAD REQUEST
Content-Type: application/json
Content-Length: 134
Server: Eve/1.0 Werkzeug/0.16.0 Python/3.7.3
Date: Thu, 23 Jan 2020 16:56:02 GMT

{"_status": "ERR", "_error": {"code": 400, "message": "The browser (or proxy) sent a request that this server could not understand."}}

如果我尝试使用国家/地区进行查询,则有效:

curl -i http://localhost:5000/banned?where=country=='VE'
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 854
X-Total-Count: 2
Last-Modified: Thu, 23 Jan 2020 16:24:42 GMT
Server: Eve/1.0 Werkzeug/0.16.0 Python/3.7.3
Date: Thu, 23 Jan 2020 19:57:04 GMT

{"_items": [{"_id": "5e29c8c3def61367e225e6c8", "ip": "8.8.8.5", "host": "test-work", "country": "VE", "jail": "SSH", "_updated": "Thu, 23 Jan 2020 16:24:35 GMT", "_created": "Thu, 23 Jan 2020 16:24:35 GMT", "_etag": "7c6598e85b4977f7ef90d586ec2c9d3a9731878e", "_links": {"self": {"title": "Banned", "href": "banned/5e29c8c3def61367e225e6c8"}}}, {"_id": "5e29c8cadef61367e225e6c9", "ip": "8.8.8.8", "host": "test-work", "country": "VE", "jail": "SSH", "_updated": "Thu, 23 Jan 2020 16:24:42 GMT", "_created": "Thu, 23 Jan 2020 16:24:42 GMT", "_etag": "dfb770fa9837322896a5bd70768e3445ae29ce2b", "_links": {"self": {"title": "Banned", "href": "banned/5e29c8cadef61367e225e6c9"}}}], "_links": {"parent": {"title": "home", "href": "/"}, "self": {"title": "banned", "href": "banned?where=country==VE"}}, "_meta": {"page": 1, "max_results": 25, "total": 2}}

有什么解决方法可以通过 ip 进行此查询吗?或者也许我需要使用 CIDR 格式保存此字段?

最佳答案

似乎您只需将 URL 用双引号引起来,例如 curl -i "http://localhost:5000/banned?where=ip=='8.8.8.8'"

关于Python-夏娃 : query to ip address saved like string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59886247/

相关文章:

node.js - 所有连接在应用程序提供服务之前连接

mongodb - 为什么我无法在 docker-compose 中使用 azure 文件共享将 mongodb 数据存储在 Azure 容器实例中?

python - 如何下载带有 sas url 的所有 blob 文件?

python - Tensorflow如何计算输出相对于输入的梯度?

python - 如何用授权码换取访问 token Twitter API?

node.js - Mongoose 切片数组,在填充字段中

python - Tensorflow Inception_Resnet_V2 分类图像

python - 在 Eve 中,如何创建集合的子资源并保留父集合端点?

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

python - 如何定义自定义过滤器并将其绑定(bind)到资源端点