简体   繁体   中英

python sys.argv[1] list index out of range

I want to send data with php and get with python. But shell_exec cannot send parameter. I cannot understand where is the problem. this does not fix my error

this is my php file

    <?php
    if(isset($_POST["username"])){
        $nick = $_POST["username"];
    echo $nick;//prints ozan to webpage
  $res = shell_exec("C:\Python27\python.exe C:\wamp\www\MLWebsite\website\new.py '".$nick."'");
        echo $res;
    }
    ?>

new.py

#!c:/Python27/python.exe
print("Content-Type: text/html")
print("""
  <TITLE></TITLE>
  <H1></H1>
"""
)

import pymysql.cursors
import sys
import json
import urllib2, urllib
import requests

x = sys.argv[1]
print x

Error

Content-Type: text/html

Traceback (most recent call last): File "C:\\wamp\\www\\MLWebsite\\website\\new.py", line 15, in x = sys.argv 1 IndexError: list index out of range

Please help me to solve this problem

这应该做

$res = shell_exec('C:\Python27\python.exe C:\wamp\www\MLWebsite\website\new.py ' . $nick);

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