-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: must be str, not bytes #7
Comments
Initially, I would get the error. After using
It appears that some extraneous 'b' is being output. Is that 'b' for byte? Edit: YES, it is the Python representation of a byte sequence. The change in handling of bytes vs strings in Python 3 (where it's now more strict) is the cause of this (compatibility) issue. |
It doesn't seem to matter whether I use Python 3.6.8 or Python 3.11, I still get the 'b' (byte) output even when trying to format() or use text=True in subprocess.check_output() Even trying 'f strings' still gives the same output print( f"Meza {version}" )
print( f"Commit {commit}" )
print( "Mediawiki EZ Admin" ) Meza b'39.0.0-16-gcd9359f\n' |
RecapHere's what you get with an unmodified meza.py on Python 3.6.8
And Python 3.11 gives pretty much the same error:
The best I've come up with so far is to wrap a print( "Meza " + format(version.strip()) )
print( "Commit " + format(commit.strip()) )
print( "Mediawiki EZ Admin" )
print( "" )
sys.exit(0) produces (for both Python 3.6.8 and 3.11)
In Python 3.11, we can add the import subprocess
version = subprocess.check_output( ["git", "--git-dir={}/meza/.git".format(install_dir), "describe", "--tags" ], text=True )
commit = subprocess.check_output( ["git", "--git-dir={}/meza/.git".format(install_dir), "rev-parse", "HEAD" ], text=True )
print( "Meza " + version.strip() )
print( "Commit " + commit.strip() )
print( "Mediawiki EZ Admin" )
print( "" )
output = subprocess.check_output(["python", "--version"], text=True)
print(output) (note how the system Python version is 3.6.8, but we run the code with
But that code produces an error in Python 3.6.8
|
So, the open question is
Upgrading Python is discussed here |
By adding .decode() to the byte objects, we can concatenate with strings in Python 3.6.8 Later versions of subprocess.check_output() can return text if you want, but not in this version.
Responses:
|
Progress:) |
By adding .decode() to the byte objects, we can concatenate with strings in Python 3.6.8 Later versions of subprocess.check_output() can return text if you want, but not in this version. This work was performed for NASA GRC-ATF by WikiWorks per NASA Contract NNC15BA02B.
meza --version
in the code for
meza.py
The
version
andcommit
are byte objects. We must use theformat
method to convert them to string before we can concatenate them to the string values (e.g. 'Meza ')The text was updated successfully, but these errors were encountered: