Python Forum
Error sending and receiving a base 64 encoded image to an API
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error sending and receiving a base 64 encoded image to an API
#1
Hello, I am implementing a facial recognition API in flask, and I need it to receive a base64 encoded image, once I receive it I decode it to process it. In the client I send the image with this code

cv2.imwrite ('image.jpg', frame)
img = open ('image.jpg', 'rb')
frame = img.read ()
if __name__ == "__main__":
    response = requests.post ('http: // localhost: 5001 / server / recognize', json = {'image': str (base64.encodestring (frame))}). json ()
But when receiving it in the microservice, with this code:

imgbase64 = request.json ["image"]
frame = base64.decodestring (imgbase64)
When sending the response I had to cast the encoded image to string because if I send it in byte format it is not accepted by the json format. Now it happens that when it is received by the microservice, since it had to be cast to string, it does not support the parameter when decoding it with the base64.encodestring () method, so when consuming the microservice it returns the error:
Error:
Expecting value: line 1 colum1 char(0)
Please excuse my bad English, I speak Spanish and I use google translator. If someone can help me solve the problem, please wait for your response.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error for convert image PIL to CV2 karlo123 2 4,754 May-07-2018, 03:14 AM
Last Post: karlo123
  Error while running python script to get pixel points from google static map image python_newbee 3 4,802 Sep-15-2017, 06:25 AM
Last Post: python_newbee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020