Python-Eve: 查询以字符串形式保存的 ip 地址

Python-Eve: query to ip address saved like string

我有这个架构:

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'".