So I built an API which takes in a pdf file and json and converts the file into text. Testing with Postman works fine, however now I try to make a script to send multiple images and the API does not receive the image I send it in the script. It receives the request but not its contents. Additionally I don't get the json file either, while it does show on the script side.
I looked at the Postman request and implemented it in the script, however it still does not work. I tried sending only the file without a json and could not get it working. I've been looking in the documentation of flask and request, but I'm not able to find the explanation why it does not receive the image.
#Script code
import requests
import time
import glob
url = "http://127.0.0.1:5000/transcribe"
for file in glob.glob("/Receipts_to_scan/*.pdf"):
print(open(file, "rb"))
files = {
'file': open(file, 'rb'),
'json': '{"method":"sypht"}'
}
headers = {
'Accept': "application/pdf",
'content-type': "multipart/form-data",
'Connection': 'keep-alive'
}
response_decoded_json = requests.post(url, files=files, headers=headers)
time.sleep(5)
print(response_decoded_json)
#--------------------------
#API code
from flask import Flask, request
@app.route("/transcribe", methods = ["POST"])
def post():
#Getting the JSON data with all the settings in it
json_data = request.files["json"]
print(json_data)
image = request.files["file"]
print(image)