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.

brain storm
  • 28,253
  • 60
  • 207
  • 376
  • 1
    Does your script have permissions to do `yum install`? You can also redirect stderr to stdout to see all output. – grundic May 08 '17 at 19:36

2 Answers2

1

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

grundic
  • 4,236
  • 3
  • 28
  • 45
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.

Community
  • 1
  • 1
Billy
  • 4,716
  • 2
  • 23
  • 48