Created 02-11-2016 01:41 PM
I am working through this tutorial and I'm encountering the error shown below. I see that others have experienced it to from looking at the comments below the walk through. I believe I have successfully completed this tutorial before. Any ideas on how to resolve this?
[root@sandbox home]# python generate_logs.pyFile “generate_logs.py”, line 98return resultsSyntaxError: ‘return’ outside function
Created 02-11-2016 02:50 PM
Just downloaded and ran the generate_logs file in the sandbox and it works fine for me. Are you sure you didn't modify the script somehow? Sometimes python is very sensitive to tab changes. Its easy for a return to suddenly be a couple characters more to the left or right and with that not in the function anymore.
Created 02-11-2016 02:50 PM
Just downloaded and ran the generate_logs file in the sandbox and it works fine for me. Are you sure you didn't modify the script somehow? Sometimes python is very sensitive to tab changes. Its easy for a return to suddenly be a couple characters more to the left or right and with that not in the function anymore.
Created 02-11-2016 02:58 PM
@Benjamin Leonhardi Thanks Benjamin. I'm currently completing the lengthy re-download and install of the SBX and will also re-download the script. Will let you know if I still receive an error.
Created 02-11-2016 03:02 PM
And if you do and still have the problem, have a look into the script file. It is not that long and it should be pretty obvious if a return is not lined up with the function before it. The comment says that he saw some intendation errors. Since I do not have the problems they must have been added perhaps by opening the file in Windows or something. Or there was a bad version hosted that was updated? Not sure.
Created 02-11-2016 03:28 PM
@Benjamin Leonhardi I'm almost at the part where I should run the script. However, Ive noticed two other items about the tutorial.
Created 02-11-2016 03:30 PM
@Benjamin Leonhardi Same error message received. Below is what is in the script which I re-downloaded and unzipped. I would paste the code from the script but it exceeds the 600 character limit. Instead Ive attached pictures. I see no issues with indentation of return statements nor do I see anything on line 98.
Created 02-11-2016 03:52 PM
Can you have a look at the file in the sandbox ( cat vi ). Might be different from windows ( Thats notepad++ right? )
Created 02-11-2016 04:01 PM
@Benjamin Leonhardi Interesting! You are right, I was using Notepadd++. However, when I opened the script in vi, there are additional lines not visible in Notepad++. See the attached picture. I changed the return on line 98 to be commented as suggested on the tutorial comments and the script executed.py3.png
Created on 02-11-2016 04:05 PM - edited 08-19-2019 01:37 AM
Did it also generate the logs? Its a bit weird, that is what I just downoaded from the tutorial link:
So for me it needed the return, it needs to be in the same line as the for and I don't have the main at the top you have.
Created 02-11-2016 04:23 PM
@Benjamin Leonhardi The main() at the top of mine is the one at the bottom of yours. My screenshot from vi is showing that line plus additional lines which were not visible in Notepad++. Sadly, no, nothing is being written to /flume/events