0

My client.py is as follows:

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)

My server.py is as follows:

@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

When I am running the client locally(127.0.0.1:5000), on my machine as well as the server where the API resides, I am getting the desired results.

However, when I run the client.py from my local machine to the remote API machine, I get an error

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

indicating the image is missing or not read. I got this confirmed when I removed the comments before rows,cols,channels = image.shape

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

The versions of OpenCV is the same on both local and remote, and the OS is ubuntu 14.04 on both the machines.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Apricot
  • 2,925
  • 5
  • 42
  • 88
  • Where do you get error? `server` or `client`? Where are your metioned comments before `rows,cols,channels = image.shape`? Where does your error print? What is the output of `print(request.files['image_data'])`? – Sraw Jul 20 '18 at 06:19
  • @Sraw The error is from the server...the error prints on the client – Apricot Jul 20 '18 at 06:22

0 Answers0