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

Community
  • 1
  • 1
Ian Smith
  • 879
  • 1
  • 12
  • 23
  • 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. – user2357112 Mar 25 '17 at 06: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. – Ian Smith Mar 25 '17 at 06:22

1 Answers1

1

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

Source

Community
  • 1
  • 1
ShaneOH
  • 1,454
  • 1
  • 17
  • 29
  • 1
    Awesome, thanks. I really wish they could add some hints to Python error messages to point out things like this. – Ian Smith Mar 25 '17 at 06:34