PythonEve:查询到像字符串一样保存的ip地址

2024-09-28 23:02:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个模式:

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

如果我尝试使用country进行查询,则有效:

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格式保存此字段


Tags: iphoststringtitletypevecontentcurl