• 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 image=@111.png 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>
    
  • 相关阅读:
    如何学习自动化测试?
    Jenkins中,执行py文件,python找包的路径(找不到自定义包的问题解决)
    数据库的架构设计
    iOS密码框的实现方式
    UISearchController 的大坑
    <第三方>TGRefreshO按照QQ的刷新方式下拉刷新
    关于项目颜色和字体的宏定义
    <iOS 导航栏>第一节:导航栏透明方法实现代码
    <iOS小技巧>UIview指定设置控件圆角
    关于这次KPL春季决赛的感悟
  • 原文地址:https://www.cnblogs.com/zgqcn/p/14406466.html
Copyright © 2020-2023  润新知