Hi,
I'm trying to understando how API are called from a different program. In this case from a PHP file.
The php file works but the .py file is just not responding as I wanted and cannot find the error.
I appreciate some help.
TIA
I'm trying to understando how API are called from a different program. In this case from a PHP file.
The php file works but the .py file is just not responding as I wanted and cannot find the error.
I appreciate some help.
TIA
import urllib.parse as ur import os sent_query = os.environ['QUERY_STRING'] query_list = sent_query.split('=') query_dict = ur.parse_qs(sent_query) def greeter(name, surname): return ('Hello ' + str(name).capitalize() + ' ' + str(surname).capitalize() + ' how are you?') input_name = str(query_dict['name'])[2:-2] input_surname = str(query_dict['surname'])[2:-2] print("Content-Type: text/html\n") print(str(greeter((input_name, input_surname))))
<?php $html_template = '<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport " content="width=device-width, initial-scale=1.0"> <title>Greeter</title> </head> <body onload=""> <form action="" method="post"> <input type="text" value="{VALUE_NAME}" placeholder="Name" name="name" id="name"><br/><br/> <input type="text" value="{VALUE_SURNAME}" placeholder="Surname" name="surname" id="surname"><br/><br/> <input type="submit" value="Greet"> </form> </body> </html>'; // echo $html_template; $input_name = (array_key_exists('name', $_POST)) ? $_POST['name'] : ""; $input_surname = (array_key_exists('surname', $_POST)) ? $_POST['surname'] : ""; $html_output = str_replace("{VALUE_NAME}", $input_name, $html_template); $html_output = str_replace("{VALUE_SURNAME}", $input_surname, $html_output); echo $html_output; //print_r($_POST); $greeter_link = "http://localhost:81/test/php_api.py?name=" . $input_name . "&surname=" . $input_surname; //echo $greeter_link; $greeter_data = file_get_contents($greeter_link); echo "<br/><br/>" . $greeter_data; ?>