【问题标题】:Python-Eve: query to ip address saved like stringPython-Eve:查询以字符串形式保存的 IP 地址
【发布时间】:2020-01-23 20:02:13
【问题描述】:

我有这个架构:

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 格式保存这个字段?

【问题讨论】:

  • 我在这里也用 eve 1.0 进行了测试,它工作正常。也许您需要转义引号?我用双引号括住 URL:curl -i "http://localhost:5000/banned?where=ip=='8.8.8.8'"
  • 是的,它正在使用:curl -i "http://localhost:5000/banned?where=ip=='8.8.8.8'" 非常感谢
  • 好。作为答案发布。

标签: python mongodb eve


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-28
    • 2017-04-02
    • 1970-01-01
    • 2011-03-28
    • 2020-10-22
    • 2019-08-25
    • 1970-01-01
    相关资源
    最近更新 更多