Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Restful读取文件_Python_Api_Flask_Flask Restful - Fatal编程技术网

Python Restful读取文件

Python Restful读取文件,python,api,flask,flask-restful,Python,Api,Flask,Flask Restful,我有一个困难:当我发布请求时,我想访问文件的内容 client.py url = 'http://127.0.0.1:5000/sendimage/test.jpg' filename = url.split('/')[-1] print filename files = {'media': open(filename, 'rb')} response = requests.post(url, files=files) server.py from flask import Flask, re

我有一个困难:当我发布请求时,我想访问文件的内容

client.py

url = 'http://127.0.0.1:5000/sendimage/test.jpg'
filename = url.split('/')[-1]
print filename
files = {'media': open(filename, 'rb')}
response = requests.post(url, files=files)
server.py

from flask import Flask, request
from flask_restful import Api, Resource, reqparse
import json

app = Flask(__name__)
api = Api(app)

class sendImage(Resource):

    def post(self, pathImg):
        print "Receiving Image ..."
        # Extraction of the sent file
        return "null"

api.add_resource(sendImage, '/sendimage/<pathImg>')

if __name__ == '__main__':
    app.run(port='5000')
从烧瓶导入烧瓶,请求
从flask_restful导入Api、资源、reqparse
导入json
app=烧瓶(名称)
api=api(应用程序)
类sendImage(资源):
def post(自我,路径):
打印“接收图像…”
#提取发送的文件
返回“null”
api.add_资源(sendImage,“/sendImage/”)
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
应用程序运行(端口='5000')
问题是:
server.py如何读取client.py发送的文件中的数据???

它应该在
request.files['media']

您可以阅读有关上传文件的完整文档,其中包含flask docs中的示例