question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

incorrect input for cmd subprocess.check_ouput() in distro.py

See original GitHub issue

Environment

  • pip version: 10.0.1
  • Python version: 3.5
  • OS: ubuntu 16.04

Description

The input cmd = ('lsb_release', '-a') on line 997 of distro.py is not a correct input for stdout = subprocess.check_output(cmd, stderr=devnull) on the line right after. It should instead be cmd = 'lsb_release; -a'.

See https://docs.python.org/3.5/library/subprocess.html#subprocess.check_output

Expected behavior

Pip does not install or uninstall.

How to Reproduce

I can’t with 100% give a way to reproduce as it only occurred when I upgraded pip. I changed that line myself and it worked.

I’ve cloned the distro repo and ran the tests. The tests resulted in 132 failures, and 34 passes. Most of the failures seem to be caused from that same issue. After making the change to that line mentioned in the description, that particular test passed.

Test results can be found here: https://pastebin.com/3UCfA2Au

Output

This is the output when it failed to install the bcrypt package

Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/pip/_internal/basecommand.py", line 228, in main
    status = self.run(options, args)
  File "/usr/local/lib/python3.5/dist-packages/pip/_internal/commands/uninstall.py", line 46, in run
    with self._build_session(options) as session:
  File "/usr/local/lib/python3.5/dist-packages/pip/_internal/basecommand.py", line 81, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/usr/local/lib/python3.5/dist-packages/pip/_internal/download.py", line 338, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/lib/python3.5/dist-packages/pip/_internal/download.py", line 101, in user_agent
    zip(["name", "version", "id"], distro.linux_distribution()),
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/distro.py", line 120, in linux_distribution
    return _distro.linux_distribution(full_distribution_name)
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/distro.py", line 634, in linux_distribution
    self.version(),
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/distro.py", line 688, in version
    self.lsb_release_attr('release'),
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/distro.py", line 836, in lsb_release_attr
    return self._lsb_release_info.get(attribute, '')
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/distro.py", line 522, in __get__
    ret = obj.__dict__[self._fname] = self._f(obj)
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/distro.py", line 933, in _lsb_release_info
    stdout = subprocess.check_output(cmd, stderr=devnull)
  File "/usr/lib/python3.5/subprocess.py", line 626, in check_output
    **kwargs).stdout
  File "/usr/local/lib/python3.5/dist-packages/run/__init__.py", line 145, in __new__
    process = cls.create_process(command, stdin, cwd=cwd, env=env, shell=shell)
  File "/usr/local/lib/python3.5/dist-packages/run/__init__.py", line 121, in create_process
    shlex.split(command),
  File "/usr/lib/python3.5/shlex.py", line 273, in split
    return list(lex)
  File "/usr/lib/python3.5/shlex.py", line 263, in __next__
    token = self.get_token()
  File "/usr/lib/python3.5/shlex.py", line 90, in get_token
    raw = self.read_token()
  File "/usr/lib/python3.5/shlex.py", line 118, in read_token
    nextchar = self.instream.read(1)
AttributeError: 'tuple' object has no attribute 'read'
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.5/dist-packages/pip/__main__.py", line 19, in <module>
    sys.exit(_main())
  File "/usr/local/lib/python3.5/dist-packages/pip/_internal/__init__.py", line 246, in main
    return command.main(cmd_args)
  File "/usr/local/lib/python3.5/dist-packages/pip/_internal/basecommand.py", line 264, in main
    timeout=min(5, options.timeout)) as session:
  File "/usr/local/lib/python3.5/dist-packages/pip/_internal/basecommand.py", line 81, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/usr/local/lib/python3.5/dist-packages/pip/_internal/download.py", line 338, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/lib/python3.5/dist-packages/pip/_internal/download.py", line 101, in user_agent
    zip(["name", "version", "id"], distro.linux_distribution()),
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/distro.py", line 120, in linux_distribution
    return _distro.linux_distribution(full_distribution_name)
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/distro.py", line 634, in linux_distribution
    self.version(),
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/distro.py", line 688, in version
    self.lsb_release_attr('release'),
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/distro.py", line 836, in lsb_release_attr
    return self._lsb_release_info.get(attribute, '')
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/distro.py", line 522, in __get__
    ret = obj.__dict__[self._fname] = self._f(obj)
  File "/usr/local/lib/python3.5/dist-packages/pip/_vendor/distro.py", line 933, in _lsb_release_info
    stdout = subprocess.check_output(cmd, stderr=devnull)
  File "/usr/lib/python3.5/subprocess.py", line 626, in check_output
    **kwargs).stdout
  File "/usr/local/lib/python3.5/dist-packages/run/__init__.py", line 145, in __new__
    process = cls.create_process(command, stdin, cwd=cwd, env=env, shell=shell)
  File "/usr/local/lib/python3.5/dist-packages/run/__init__.py", line 121, in create_process
    shlex.split(command),
  File "/usr/lib/python3.5/shlex.py", line 273, in split
    return list(lex)
  File "/usr/lib/python3.5/shlex.py", line 263, in __next__
    token = self.get_token()
  File "/usr/lib/python3.5/shlex.py", line 90, in get_token
    raw = self.read_token()
  File "/usr/lib/python3.5/shlex.py", line 118, in read_token
    nextchar = self.instream.read(1)
AttributeError: 'tuple' object has no attribute 'read'

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
HassanBakercommented, Feb 8, 2020

@HarshitRuwali uninstall subprocess.run

Gonna close this issue also ✌️

3reactions
asottilecommented, Feb 8, 2020

there should be no need to install subprocess, it is part of the python standard library

Read more comments on GitHub >

github_iconTop Results From Across the Web

Performance of subprocess.check_output vs subprocess.call
The subprocess I'm executing is a shell script which eventually fires off a Windows python.exe process via Wine (why this foolishness is ...
Read more >
Issue 3905: subprocess failing in GUI applications on Windows
I'm getting a 'The handle is invalid' error when using subprocess. ... path in subprocess.py then calls `DuplicateHandle` on this in `Popen.
Read more >
The subprocess Module: Wrapping Programs With Python
Issue shell commands like ls or dir; Feed input into a process and use its output. Handle errors when using subprocess; Understand the...
Read more >
Subprocess management — IronPython 2.7.2b1 documentation
Executing shell commands that incorporate unsanitized input from an ... On Windows: the Popen class uses CreateProcess() to execute the child child program, ......
Read more >
Calling Shell Commands from Python: OS.system vs ...
If you are a Python programmer, it is quite likely that you have ... use as input of the function the same command...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found