0

我的client.py如下:

import requests
with open("image.jpg", "rb") as imageFile:
#   fil=imageFile.read()
#   print(fil) 
    url = 'http://10.7.104.57:5000/julytest'
    headers = {'Content-Type': 'application/octet-stream'}
    try:
        response = requests.post(url, files=[('image_data',('image.jpg', imageFile, 'image/jpg'))])
    except Exception as e:
        print(e)
print(response.text)

我的 server.py 如下:

@app.route('/julytest', methods=['GET', 'POST'])
def get():
    print(request.files['image_data'])
    img = request.files['image_data']
    fil = img.filename
    image = cv2.imread(img.filename)
    rows, cols, channels = image.shape
    #do other processing

当我在本地(127.0.0.1:5000)、我的机器以及 API 所在的服务器上运行客户端时,我得到了想要的结果。

但是,当我从本地机器运行 client.py 到远程 API 机器时,出现错误

 error: (-215) (scn == 3 || scn == 4) && (depth == 0 || depth == 5) in function cvtColor

表示图像丢失或未读取。当我之前删除评论时,我得到了证实rows,cols,channels = image.shape

AttributeError: 'NoneType' object has no attribute 'shape'

本地和远程的 OpenCV 版本相同,两台机器上的操作系统都是 ubuntu 14.04。

4

0 回答 0