微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

flask 图像接口测试

方法一:requests

import requests, time

class PicApi():
    def requests_post(self, path):
        url = self.url + '/get_result'
        files = {'image':open(path,'rb'),
                 'filename':path[:path.index('.')]}
        Feed_back = str(requests.post(url,files=files).content)
        if '400' not in Feed_back:
            print('【Info LOG】{} 图片上传成功!'.format(time.strftime('%Y-%m-%d %H:%M:%s',time.localtime())))
            return True
        else:
            print('【Info LOG】{} 图片上传失败,返回信息:{}!'.format(time.strftime('%Y-%m-%d %H:%M:%s',time.localtime()),Feed_back))
            return False

    def request_download(self, path, opt):
        import requests
        if opt=='X2':
            r = requests.get(self.url+'/static/output/X2/X2_'+ path +'.png')
            with open('X2.png', 'wb') as f:
                f.write(r.content)
        else:
            r = requests.get(self.url+'/static/output/X4/X4_'+ path +'.png')
            with open('X4.png', 'wb') as f:
                f.write(r.content)
            
    def main(self, url, path, opt='X2'):
        self.url = url
        flag = self.requests_post(path)
        if flag:
            self.request_download(path, opt)
            print('【Info LOG】{} 图片下载成功!'.format(time.strftime('%Y-%m-%d %H:%M:%s',time.localtime())))

PA = PicApi()
PA.main('http://7a337874388e.ngrok.io','111.png')

Thanks for Lin YuCheng.

方法二:curl

!curl -X POST -F [email protected] http://7a337874388e.ngrok.io/get_result

在利用正则化从HTML中进行爬取

<body>
    <div align="center">
        <h1>Super Resolution Image</h1>

        
            <div class="row" align="center">
                <div class="column">
                    <h1>Output Image X2</h1>
                    <img src="static/output/X2/X2_111.png.png" height=512px width=512px />

                    <form action="/static/output/X2/X2_111.png.png" method="get" enctype='multipart/form-data'>
                        <input class="input" type="submit" name="download" value="Download">
                    </form>

                </div>


                <div class="column">
                    <h1>Output Image X4</h1>
                    <img src="static/output/X4/X4_111.png.png" height=512px width=512px />

                    <form action="/static/output/X4/X4_111.png.png" method="get" enctype='multipart/form-data'>
                        <input class="input" type="submit" name="download" value="Download">
                    </form>
                </div>

                <form action="/" method="get" enctype='multipart/form-data'>
                        <input class="input" type="submit" name="Continue" value="Continue">
                </form>

            </div>
        
    </div>
</body>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐