marker icon indicating copy to clipboard operation
marker copied to clipboard

TypeError: cannot use a string pattern on a bytes-like object

Open X1011 opened this issue 9 years ago • 6 comments

When trying to run install.py, i get this error:

Traceback (most recent call last):
  File "./install.py", line 109, in <module>
    main()
  File "./install.py", line 81, in main
    verify_requirements()
  File "./install.py", line 61, in verify_requirements
    m = re.search('(\d).(\d)', version_text)
  File "/usr/lib/python3.5/re.py", line 173, in search
    return _compile(pattern, flags).search(string)
TypeError: cannot use a string pattern on a bytes-like object

On my system, when using pipes, i do sometimes get this weird error message (line 2 below). I haven't been able to figure out the cause, but i haven't seen any side effects from it before now, so i don't know if it is the problem here:

$ bash --version | head -1
bash: child setpgid (20301 to 20297): Operation not permitted
GNU bash, version 4.3.42(1)-release (x86_64-unknown-linux-gnu)

Here's what i get in the REPL:

$ python
Python 3.5.0 (default, Sep 20 2015, 11:28:25) 
[GCC 5.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.Popen("bash --version | head -1", shell=True, stdout=subprocess.PIPE).stdout.read()
b'GNU bash, version 4.3.42(1)-release (x86_64-unknown-linux-gnu)\n'

X1011 avatar Dec 21 '15 23:12 X1011

It works if i change line 60 to set version_text manually:

version_text = "GNU bash, version 4.3.42(1)-release (x86_64-unknown-linux-gnu)"

X1011 avatar Dec 22 '15 00:12 X1011

hmm, yes. the first line in bash --version is expected to be the version string. But in your case there is an error(or warning, I'm not sure): bash: child setpgid (20301 to 20297): Operation not permitted

pindexis avatar Dec 30 '15 12:12 pindexis

but that error message goes to stderr, not stdout:

$ bash --version | head -1 >/dev/null 
bash: child setpgid (9003 to 8999): Operation not permitted
$ (bash --version | head -1) 2>/dev/null
GNU bash, version 4.3.42(1)-release (x86_64-unknown-linux-gnu)

so install.py shouldn't be reading in that line, right?

X1011 avatar Jan 04 '16 03:01 X1011

I got the same issue. It happens because you use a string pattern on a bytes object. Replace line 61 with following line will fix this issue:

m = re.search(b'(\d).(\d)', version_text)

et2010 avatar Jan 31 '16 13:01 et2010

I fixed this error by using Python 2.

NightMachinery avatar Sep 10 '18 17:09 NightMachinery

I just got this issue too

dessalines avatar Feb 07 '19 23:02 dessalines