Search code examples
pythonpython-3.xpraw

TypeError: cannot concatenate 'str' and 'Redditor' objects


Traceback (most recent call last):
  File "run.py", line 56, in <module>
    run(r, comments_replied_to)
  File "run.py", line 30, in run_bot
    b.write("Author=" + comment.submission.author + "\n")
TypeError: cannot concatenate 'str' and 'Redditor' objects

This is the traceback recieved from the code, I'm not sure how to fix this, thank you.

Here's the code

with open ("first.txt", "a") as f, open 
    ("second.txt", "a") as b:
        f.write(comment.id + "\n")
            b.write("author=" + comment.submission.author + "\n")

Solution

  • I guess you're using PRAW and want to get the reddit username? Right now, you're trying to concatenate a String with the Redditor object.

    Instead, you need to use Redditor.name to access the username. Have a look at the docs for the Redditor object.

    In your case that would be

    comment.submission.author.name