1

when I execute the following function in centos, I get the error

def install_requests_lib():
   try:
      import requests
      return
   except ImportError, e:
      print "module does not exist, installing..."
      if(platform.system().lower()=='darwin'):
          print "install requests before proceeding, run **sudo pip install requests**"
          sys.exit(2)
      elif(platform.system().lower()=='linux'):
          print "installing"
          p=Popen(["yum","-y","install","python-requests"], stdout=PIPE, shell=True)
          p.communicate()
          print p.returncode

error:

module does not exist, installing...
installing
You need to give some command
1

I cannot figure out what is wrong.

I executed with stdin=PIPE argument, still I get the same error.

1
  • 1
    Does your script have permissions to do yum install? You can also redirect stderr to stdout to see all output. Commented May 8, 2017 at 19:36

2 Answers 2

1

The arguments in your arg list after "yum" aren't being executed if you give the argument shell=True. Remove the shell=True argument and it should work.

Alternatively, you could supply the full command line as a string and keep the shell=True argument:

p=Popen("yum install -y python-requests", stdout=PIPE, shell=True)

but it's generally discouraged to do so, for many reasons.

Sign up to request clarification or add additional context in comments.

Comments

1

You are trying to execute yum -y install, when you mean yum install -y.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.