简体   繁体   中英

python subprocess function can't find path: php file

Embarked on aws lambda platform, attempted running python sub process function for invoking php url, which did not yield the desired outcome. Here given below the code for your ready reference:

import json
import subprocess

# if the script don't need output.

subprocess.call('php https://mbracecloud.com/post_form.php', stdin=None, stdout=None, stderr=None, shell=False)

On running this code, we encounter this error:

"errorMessage": "[Errno 2] No such file or directory: 'php https://mbracecloud.com/post_form.php'",
  "errorType": "FileNotFoundError",

Though the file exists, it is displaying error "file not found"

Edit:

Okay based on what maurice said, followed the new code of python standard library from another thread. Ran the code below:

import requests
r = requests.post("http://bugs.python.org", data={'number': 12524, 'type': 'issue', 'action': 'show'})
print(r.status_code, r.reason)

There seems to some problem with import "request". How do i overcome this?

Response:
{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'requests'",
  "errorType": "Runtime.ImportModuleError"
}

What you're telling the python interpreter to do is running the command php https://... in your Lambda Runtime Environment. Unless you're using a custom runtime, php won't be installed in the Lambda Execution Context . That's why it results in a FileNotFoundError when you try to execute php .

I assume what you're actually trying to do is call the API behind the URL you mention, for that you can use the python standard library. This answer has an example for that.

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