Reputation: 11
So, my problem is :
I have a file (data_test.json)
on the web. I wrote and uploaded it myself.
{
"a" : 1,
"b" : 42,
"c" : 3.14
}
My local python code in Renpy read it rightly.
init python:
def get_stats():
# Déclaration des variables
global test_a
global test_b
global test_c
# Importation des modules
import requests
import json
# Atteindre le fichier
r = requests.get("https://lecot-christophe.com/rpu_json/data_test.json")
# Aquérir les données sous forme de texte
r.text
# Convertir en dictionnaire Python
var = json.loads(r.text)
# Boucler pour extraire et distribuer les résultats à travers les variables
for i in var:
test_a = var['a']
test_b = var['b']
test_c = var['c']
Then the python code makes an update. I think python send rightly the data cause of the response of the requests. post is positive.
def post_stats(file):
global test_a
global test_b
global test_c
global send_test
import requests
import json
url = "https://*monsite*/rpu_json/renpy_json_manager.php"
# Composition des données
file_name = file+".json"
aDict = {
"a":test_a,
"b":test_b,
"c":test_c
}
json_object = json.dumps(aDict)
# Adresser le fichier
data_test = requests.post(url, json=json_object)
send_test = data_test.status_code
PHP receive the posted data or not, and update the json file.
<?php
$json = $_POST['data'];
$info = json_encode($json);
$file = fopen('data_test.json','w+') or die("File not found");
fwrite($file, $info);
fclose($file);
?>
But the content of data-test.json is now just "null".
null
So... Where did I make a big mistake ?
Upvotes: 1
Views: 122