I am using this code to read a json file in subprocess. It does work for only small jsons, If it exceeds over 33766 count. it will show a error showing

FileNotFoundError: [WinError 206] The filename or extension is too long.

this is beccause of exceeding 33766 count. so how to read the json file using popen .Read that this can solve the problem. Help me with suggestions. I am new here :\

import subprocess
import json
import os

from pprint import pprint

auth = "authorization: token 1234

file = "jsoninput11.json"
fd=open("jsoninput11.json")
json_content = fd.read()
fd.close()


subprocess.run(["grpcurl", "-plaintext","-H", auth,"-d","@",json_content,"-format","json","100.20.20.1:5000","api.Service/Method"])

1 Answers

0
Fabrizio On Best Solutions

I am not sure but maybe the problem is related to the bufsize (check this: Very large input and piping using subprocess.Popen ) Does it works with capture_output=False?

subprocess.run(["grpcurl", "-plaintext","-H", auth,"-d","@",json_content,"-format","json","100.20.20.1:5000","api.Service/Method"], capture_output=False)

On the other side, if you need the output you may need to deal with the PIPE of Popen.