0

The answer on this post, https://stackoverflow.com/a/16175368/6448312 is failing to run for me on Python 3. I'm getting the error of -

#$>test2.py Traceback (most recent call last):   File "C:\Users\.\OneDrive\PROJECTS for fun\smartApp\test2.py", line 4, in <module>
for row in output.split('\n'): TypeError: a bytes-like object is required, not 'str'

I am using the same code they posted - https://hastebin.com/ubafadikos.py

It seems like I need to cast the string to a byte type, I've tried using, newOutput = bytes(output, 'utf-8') but that is failing too with the error message of

newOutput = bytes(output, 'utf-8')
TypeError: str() takes at most 1 argument (2 given)

I'm at a loss for what to try next :( I'm using Python 3.6.1, running the code on Python 2.7 works fine.

EDIT: Using newOutput = bytes(output) works

2
  • Your first error message looks like a Python 3 error message, but your second error message looks like a Python 2 error message. Something's really weird about how you're running this code. Commented Mar 25, 2017 at 6:19
  • @user2357112 Thanks for the comment, both outputs are from Python3. I took out the second argument as it said it didn't want more than 1 for newOutput = bytes(output, 'utf-8') and the code ran successfully. However I'm not sure if that's syntactically correct. Commented Mar 25, 2017 at 6:22

1 Answer 1

1

Try for row in output.decode().split('\n')

Source

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, thanks. I really wish they could add some hints to Python error messages to point out things like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.