python - Curl not working when called with subprocess -


i'm trying call rest api curl. api endpoint dynamically generated in program , json file uploaded.

with open('data.json','w') f:     f.write(json.dumps(data))     cmd = 'curl -x put -h "content-type: application/json" -d @data.json {0}'.format(put_uri)     print cmd     p= subprocess.popen(cmd, shell=true, stdout=subprocess.pipe)     p.wait()     output, errors = p.communicate()     if p.returncode != 0:         print "request failed" 

here i'm printing command formed , when run command shell, working intended do. same command run popen throws json validation error weired

{   "success" : false,   "message" : "resource cannot parsed due unexpected character ('/' (code 47)): maybe (non-standard) comment? (not recognized 1 since feature 'allow_comments' not enabled parser)\n @ [source: java.io.stringreader@444c7495; line: 1, column: 2]" } 

this code isn't ensuring json written disk before calling curl.

either use f.flush() or f.close() following f.write(json.dumps(data)).


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -