Python OSError: [Errno 2]

Ampage Green

trying to create a test file to run two processes simultaneously. Using the subprocess module to do so. Having an issue where it says the file cannot be found, but it does not specify which file. We are using absolute filenames and can confirm that the path is correct. Can anyone tell us what this obscurity may be?

import subprocess
import random


port_num = random.randint(1049, 2000) # generates random port number
fns = open("filenames.txt").readlines() #reads in the file names
port_str = str(port_num)

for fn in fns:
    fn_nospace = fn.strip() #remove any excess spaces
    print fn_nospace
    cwdhalf = ['pwd']
    subprocess.call(cwdhalf)
    cmd1 = ['./webserver.py '+port_str] # open webserver with the input portnumber
    subprocess.check_call(cmd1) # calls cmd1
    cmd2 = ['wget localhost:'+port_str+'/'+fn_nospace] # samething with wget, only this time using the filename
    subprocess.check_call(cmd2)

The error being reported is as follows:

Traceback (most recent call last):
  File "testwebserver.py", line 26, in <module>
    subprocess.check_call(cmd1) # calls cmd1
  File "/usr/lib/python2.6/subprocess.py", line 493, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python2.6/subprocess.py", line 480, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.6/subprocess.py", line 633, in __init__
    errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1139, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
jfs

The traceback shows that the issue is with cmd1. Both commands in the code are incorrect.

The rule is simple: one list item -- one command-line parameter:

cmd1 = ['./webserver.py', port_str]
cmd2 = ['wget', 'localhost:%s/%s' % (port_str, fn_nospace)]

Also, OSError has filename, filename2 attributes that you can inspect programmatically. Though they are not set in this case.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python: try/except OSerror errno 2

From Dev

Python: try/except OSerror errno 2

From Dev

OSError [Errno 99] - python

From Dev

OSError [Errno 99] - python

From Dev

linux command produce Python OSError: [Errno 2] No such file or directory

From Dev

Python: OSError: [Errno 2] No such file or directory on subprocess.Popen

From Java

OSError: [Errno 2] No such file or directory while using python subprocess in Django

From Dev

Python Popen shell=False causes OSError: [Errno 2] No such file or directory

From Dev

ANARCI Python 2.7.13 - raise child_exception // OSError: [Errno 2]

From Dev

Python: map errno to subclass of OSError

From Dev

Odoo: OSError: [Errno 2] No such file or directory

From Dev

What is the reason for the error 'OSError: [Errno 2] No such file or directory' in ncpol2sdpa python tool?

From Dev

Python OSError: [Errno 22] Invalid argument

From Dev

Python: OSError: [Errno 22] Invalid argument: '*.txt'

From Dev

Python Popen shell=False causes OSError: [Errno 2] No such file or directory FFREPORT

From Dev

Django 1.9 : Pass variables from python script to bash script - OSError : [Errno 2] No such file or directory

From Dev

OSError: [Errno 2] No such file or directory when running systrace.py

From Dev

AWS Lambda subprocess OSError: [Errno 2] No such file or directory

From Dev

ipython notebook doesn't work: OSError: [Errno None not found] 2

From Dev

subprocess.Popen: 'OSError: [Errno 2] No such file or directory' only on Linux

From Dev

django extensions OSError: [Errno 2] "dot.exe" not found in path

From Dev

Python Selenium chromedriver OSError: [Errno 8] Exec format error

From Dev

Python error OSError: [Errno 31] Too many links

From Dev

OSError: [Errno 13] Permission denied Python subprocess.call()

From Dev

OSError: [Errno 9] Bad file descriptor in python 3

From Dev

Python CGI Script: OSError: [Errno 8] Exec format error

From Dev

python-serial OSError: [Errno 11] Resource temporarily unavailable

From Dev

python3 OSError: [Errno 107] Transport endpoint is not connected

From Dev

OSError: [Errno 13] Permission denied Python subprocess.call()

Related Related

  1. 1

    Python: try/except OSerror errno 2

  2. 2

    Python: try/except OSerror errno 2

  3. 3

    OSError [Errno 99] - python

  4. 4

    OSError [Errno 99] - python

  5. 5

    linux command produce Python OSError: [Errno 2] No such file or directory

  6. 6

    Python: OSError: [Errno 2] No such file or directory on subprocess.Popen

  7. 7

    OSError: [Errno 2] No such file or directory while using python subprocess in Django

  8. 8

    Python Popen shell=False causes OSError: [Errno 2] No such file or directory

  9. 9

    ANARCI Python 2.7.13 - raise child_exception // OSError: [Errno 2]

  10. 10

    Python: map errno to subclass of OSError

  11. 11

    Odoo: OSError: [Errno 2] No such file or directory

  12. 12

    What is the reason for the error 'OSError: [Errno 2] No such file or directory' in ncpol2sdpa python tool?

  13. 13

    Python OSError: [Errno 22] Invalid argument

  14. 14

    Python: OSError: [Errno 22] Invalid argument: '*.txt'

  15. 15

    Python Popen shell=False causes OSError: [Errno 2] No such file or directory FFREPORT

  16. 16

    Django 1.9 : Pass variables from python script to bash script - OSError : [Errno 2] No such file or directory

  17. 17

    OSError: [Errno 2] No such file or directory when running systrace.py

  18. 18

    AWS Lambda subprocess OSError: [Errno 2] No such file or directory

  19. 19

    ipython notebook doesn't work: OSError: [Errno None not found] 2

  20. 20

    subprocess.Popen: 'OSError: [Errno 2] No such file or directory' only on Linux

  21. 21

    django extensions OSError: [Errno 2] "dot.exe" not found in path

  22. 22

    Python Selenium chromedriver OSError: [Errno 8] Exec format error

  23. 23

    Python error OSError: [Errno 31] Too many links

  24. 24

    OSError: [Errno 13] Permission denied Python subprocess.call()

  25. 25

    OSError: [Errno 9] Bad file descriptor in python 3

  26. 26

    Python CGI Script: OSError: [Errno 8] Exec format error

  27. 27

    python-serial OSError: [Errno 11] Resource temporarily unavailable

  28. 28

    python3 OSError: [Errno 107] Transport endpoint is not connected

  29. 29

    OSError: [Errno 13] Permission denied Python subprocess.call()

HotTag

Archive