I am trying to transfer a dictionary from python using a function/class. I have already made a simple transfer, more information about it here and here.
So far I have the following functioning code which simply transfers the data
dictionary from Python to PHP:
Python (Basic Script)
(Must run first for PHP to work)
import sys, json, random
data = {'form_type':'default'}
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
PHP (Basic Script)
<?php
$string = file_get_contents("data.json");
$json_a = json_decode($string, true);
echo $json_a['form_type'];
?>
Python (Main Script)
I have implemented this into my main PHP page, which works fine with the simple Python script. However, the advanced python script with lots of unrelated code is not functioning. These are the first lines of that code:
import dill
import random
import sys
import os
import json
restart = 'yes'
user_action = 'inventory'
pickle = 'rpg.pickle'
restart = sys.argv[1]
user_action = sys.argv[2]
pickle = sys.argv[3] + ".pickle"
if restart == "no" and os.path.isfile(pickle) == False:
restart = "yes"
data = {'form_type':'potato'}
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
# Lots of more code afterward
This code completely crashes when run by PHP, and the JSON file is not edited and no output is received by PHP. Any ideas why this is or is more information needed to answer this question?