Search code examples
pythondockersubprocessmongoexport

mongoexport using python subprocess fails - no reacahble serves


I have a docker container (based on RHEL6) where I am running the mongoexport command line tool from a python script using the subprocess module.

mongoexport fails with exit code 1 and the error:

no reachable servers

The mongoexport command has the required connection info, such as host, port, db.

When I run the same mongoexport command in the same container using docker run, it succeeds.

Any idea what goes wrong when I run using Python?


Solution

  • The problem was related to linux/windows compatibility and the way the mongoexport command is built.

    The developer developed the Python script on Windows, where subprocess.Popen can receive the command line as a string array. In linux, however, it should be a single string argument.

    Changing the way the argument passed to subprocess.Popen to a single string fixed this problem.