【问题标题】:How can i upload a pickle file using curl to get some treatment done我如何使用 curl 上传泡菜文件以完成一些处理
【发布时间】:2021-05-27 02:05:05
【问题描述】:

我正在尝试使用 curl 上传包含一些数据的泡菜文件。我用了这个命令

curl -i -X POST -H 'Content-Type: application/json' -F 'data=@/example_data.p' http://localhost:9999/process

这是我在 /process 上的内容

@app.route('/process', methods=['GET', 'POST'])
def process():
    if request.method == 'POST':
        d = request.get_json()
        p = dict(d['payload'])
        print(p.keys())
        # print(p)
        gid = uuid.uuid4()
        Q.put({'gid': gid, 'payload': p})
        print(gid)

        r = {"id": str(gid)}
        response = app.response_class(response=json.dumps(
            r), status=200, mimetype='application/json')
        return response
if __name__ == "__main__":
    main()

这是我遇到的错误

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  904k  100   192  100  904k    901  4245k --:--:-- --:--:-- --:--:-- 4266kHTTP/1.0 400 BAD REQUEST
Content-Type: text/html; charset=utf-8
Content-Length: 192
Access-Control-Allow-Origin: *
Server: Werkzeug/2.0.0 Python/3.7.8
Date: Thu, 27 May 2021 01:56:00 GMT

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>The browser (or proxy) sent a request that this server could not understand.</p>

谁能解释一下这个问题?

【问题讨论】:

    标签: python python-3.x flask curl pickle


    【解决方案1】:

    我认为问题在于,当数据是 pickle 文件时,您正在尝试读取 json 对象 (d = request.get_json())。

    你可能想做这样的事情:

    @app.route('/process', methods=['GET', 'POST']) 
    def process():
        if request.method == 'POST':
            d = pickle.loads(request.get_data())
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-31
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多