简体   繁体   中英

How to fetch parameters from POST call in python web service

I am a python developer who is completely new to web development. I wish to develop a web service in python which authenticates user and returns a token.

I was able to do that using PHP (thanks to all the blogs available online). But soon realized that I want to do that in python.

Where I am stuck is that-

  • I don't understand how to fetch the parameters from POST request, like I was fetching in PHP (see code).
  • How to return a string or code (in PHP it's echo, should I user return ?)

     // include db connect class require_once('veggieking_connect.php'); // connecting to db $db = new VEGGIEKING_CONNECT(); // set mysql_query for utf8 mysql_query ("set character_set_results='utf8'"); $emp_id = $_POST["mEmpID"]; $emp_pwd = $_POST["mPassword"]; $result = mysql_query("select * from empdata where emp_id like '$emp_id' and emp_pwd like '$emp_pwd'") or die(mysql_error()); if(mysql_num_rows($result) > 0) { while($row = mysql_fetch_assoc($result)) { echo $row['emp_email']; } } else { echo "Fail"; } ?> 

Just like in PHP, emp_id and emp_pwd are fetched, how to do that in python web serice when I call using the same POST request in android.

I understand it's a simple question, but I can't find any good python web services examples which explains what's happening in the code. If you are aware of where I can learn these, please share the url's also, it would be really helpful. Thanks.

From your php code i understand bit that you want to retrieve and then fetch data in database. For this purpose in python use "psycopg2" module.

psycopg2 python Documentation

Using this Module you can do any operations related to database from python code. I hope this will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM