RESTful API - 只有10%的POST响应适用于相同的API

时间:2017-06-08 09:59:22

标签: python rest nginx flask gunicorn

我正在运行RESTFUL API以从POST中提取json。第三方API POSTS到我们的端点,该端点在由gunicorn服务的nginx后面的VM上的Flask环境中运行。问题是只有10%通过,如果我使用POSTMAN或卷曲它相同。我已经测试了一个剥离的api来删除任何处理但得到相同的结果。我希望每次5分钟左右的每次POST都可以通过。

我已经看过nginx配置,gunicorn配置和烧瓶配置,我要么缺少一些东西,要么就不是问题了。我们的FW将为这个VM提供任何通道。 nginx访问日志显示出90%的缺口,就像手动点击psotman帖子一样。

有什么想法吗?

烧瓶代码:

from datetime import datetime
from flask import Flask, jsonify, request, Response, json 
from functools import wraps

API_SECRET_KEY = "****"

def not_authenticate():
    message = {'message': "Not Authenticated."}
    resp = jsonify(message)
    resp.status_code = 401
    return resp

app = Flask(__name__)

# assigns route for POSTING JSON requests
@app.route('/api/v1.0/my-api1', methods=['POST'])
def m_api1():
    # AUTHENTICATION
    api_key = None
    if request.headers.get('Authorization'):
        api_key = request.headers['Authorization']
    elif request.args.get('Authorization'):
        api_key = request.args['Authorization']
    if api_key == API_SECRET_KEY:
        if request.method == 'POST':
           return "Authenticated" 
    return not_authenticate()

# assigns route for the default GET request
@app.route('/')
def index():
    return 'test on the index'  

if __name__ == "__main__":
    app.run()

nginx .conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile off;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";


    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

此处还有一个nginx访问日志文件的示例,其中显示了更频繁的404中的间歇性过度(200)...请注意,IP地址确实会从第3方api更改,但我们显然可以捕获所有内容。

*xx.xx.xx.221 - - [08/Jun/2017:07:39:45 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 200 79 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.166 - - [08/Jun/2017:07:39:46 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.139 - - [08/Jun/2017:07:44:46 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.71 - - [08/Jun/2017:07:44:46 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.81 - - [08/Jun/2017:07:49:47 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.62 - - [08/Jun/2017:07:49:47 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.88 - - [08/Jun/2017:07:54:48 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.254 - - [08/Jun/2017:07:54:48 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.68 - - [08/Jun/2017:07:59:47 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 200 79 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.81 - - [08/Jun/2017:07:59:49 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.169 - - [08/Jun/2017:08:04:47 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.62 - - [08/Jun/2017:08:04:48 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 200 79 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.69 - - [08/Jun/2017:08:09:47 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.81 - - [08/Jun/2017:08:09:48 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.31 - - [08/Jun/2017:08:14:48 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.108 - - [08/Jun/2017:08:14:48 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 200 79 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.62 - - [08/Jun/2017:08:19:47 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 200 79 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.43 - - [08/Jun/2017:08:19:49 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.166 - - [08/Jun/2017:08:24:50 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.139 - - [08/Jun/2017:08:24:50 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.33 - - [08/Jun/2017:08:29:49 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 200 79 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.40 - - [08/Jun/2017:08:29:50 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.224 - - [08/Jun/2017:08:34:50 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.166 - - [08/Jun/2017:08:34:50 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.68 - - [08/Jun/2017:08:39:49 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.37 - - [08/Jun/2017:08:39:49 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.88 - - [08/Jun/2017:08:44:49 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.97 - - [08/Jun/2017:08:44:51 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.37 - - [08/Jun/2017:08:49:51 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.221 - - [08/Jun/2017:08:50:06 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.37 - - [08/Jun/2017:08:54:52 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.221 - - [08/Jun/2017:08:54:53 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.40 - - [08/Jun/2017:08:59:54 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.106 - - [08/Jun/2017:08:59:54 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.224 - - [08/Jun/2017:09:04:54 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"
xx.xx.xx.31 - - [08/Jun/2017:09:04:55 +0100] "POST /api/v1.0/my-api1 HTTP/1.1" 404 209 "-" "3rdparty-api-webhooks/0.1"*

0 个答案:

没有答案