kii-chan-reloaded / RedTwiBot

A Reddit/Twitch bot that will update your subreddit statusbar when streamers are playing your sub's game
GNU General Public License v3.0
0 stars 0 forks source link

Either this is the first time this script is being run, or there was an error reading the config file. #1

Closed EthanC closed 7 years ago

EthanC commented 7 years ago

I receive this error every single time I restart the Python Script, the only way to get the bot to work is to go through config everytime you want the bot restarted, you are unable to even copy/paste your configuration.ini file.

To reproduce, setup the bot, let it run, then close the Python window and attempt to relaunch.

I've noticed that the order in which my credentials are in the .ini changes everytime I redo config, and I suspect this may have to do with the script having errors running the config file.

Windows 10 x64 Python 3.5.3 Latest Praw and Requests Installed

kii-chan-reloaded commented 7 years ago

Unfortunately, I don't have Win10 to test this out on, so we'll have to work together to figure this one out.

This error should have nothing to do with the modules. Also, it's worth noting that I rewrote this a few days ago, so make sure you have the most recent revision of the script before we go too much further.

Something in the loadConfig function is causing the error. There are three possible culprits:

  1. The myPath variable is improperly getting defined, so configparser doesn't find it.
  2. The config file is blank (You said it's being written to, so not this)
  3. One of your sections in the file is blank

If it's not #3, I suspect something weird is going on with #1 above. Paste this over the loadConfig function, and we'll go from there:

def loadConfig(myPath):
    """
    loads the config file, if anything is empty, cause panic
    """
    print("Loading configuration from file from '"+myPath+"configuration.ini'...")
    input()
    conf = configparser.RawConfigParser()
    conf.optionxform = lambda option: option
    conf.read(myPath+"configuration.ini")
    if not conf.sections():
        raise Exception
    print("Loaded sections. Checking for values...")
    for item in conf.sections():
        if not [thing[1] for thing in conf[item].items()]:
            raise Exception
        print("Found values for section "+item)
    print("Configuration not blank. Using "+myPath+"configuration.ini")
    return conf

This will print out where it's looking for the config file, and then freeze the script. You can press enter to continue, or just close it at that point to save yourself the trouble.

EthanC commented 7 years ago

Yes, I'm using the rewrite, newest commit. There are no blank sections in my configuration.ini either.

Starting with a fresh script, not including your modification above, will debug with that once I run into the error, going to log everything I do,

  1. Run SidebarStreamers.py (only file in the folder)
  2. Enter Reddit Bot Username
  3. Enter Reddit Bot Password
  4. Enter Reddit Bot ClientID
  5. Enter Reddit Bot Secret
  6. Enter Twitch Bot ClientID
  7. Enter Subreddit
  8. Enter My Reddit Username
  9. Enter amount of seconds
  10. Enter 1 game, for debug sake, title "Call of Duty: Infinite Warfare" (are special characters ":" messing anything up?)
  11. Enter 1 streamer, for debug sake
Config file written successfully
Bot successfully loaded. Entering main loop.
03/07/17, 21:27-
    Sidebar was updated

Here is what my config file looks like (censored, of course)

[R]
u = XXXXXXXXXXXXXX
c = XX-XXXXXXXXXXX
p = XXXXXXXXXXXXXXXXXX
s = XXXX_XXXXXXXXXXXXXXXXXXXXXX

[T]
c = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

[M]
mySub = XXXXXXXXXX
sleepTime = 60
botMaster = XXXXXXXXXXXXXXXX

[G]
call of duty: infinite warfare = True

[S]
XXXXXX = True

Script successfully ran, now I'm going to close the Python window and attempt to re-run.


Okay so, I have no idea what changed, but it ran perfectly fine lol... I'm going to comment this log assuming I'll run into the issue again. Sorry about that, I have no idea why it worked this time!

kii-chan-reloaded commented 7 years ago

No worries! I'm glad whatever it was got worked out. I'll leave this open for the time being just in case you start having problems again.

EthanC commented 7 years ago

And we're back haha! Ran into the issue again, this time it was running for roughly 12HRS, refreshing every 60s, and I just went to check on the server, stupidly didn't copy/paste the error but it was something simple like

Refreshing

Error!

     )

Refreshing

Error!

     )

and so on...

So, I assumed it was just a little problem, closed the Python window, went to run again, and we're back to the original issue.

So, here's a log of me going through the Python script using the edit you gave above:

  1. Run Python Script
  2. Hangs on Loading configuration from file from 'C:\Users\SERV\Desktop\StreamBot\configuration.ini'..., no further progress

Would my Folder Name StreamBot or even the name of the Python Script SidebarStreamers.py have anything to do with it?

Here's a copy of the entire command window after placing your edit in the script. I just pressed enter for the fun of it to see if it was maybe paused, seemingly was, still throws the same error and goes to normal config as if the configuration.ini is missing, which it is not.

Importing praw
Importing re
Importing configparser
Importing time
Importing requests
Importing json
C:\Users\SERV\Desktop\StreamBot\
Loading configuration from file from 'C:\Users\SERV\Desktop\StreamBot\configuration.ini'...

Here's a copy of the entire command window before placing your edit in the script:

Importing praw
Importing re
Importing configparser
Importing time
Importing requests
Importing json
C:\Users\SERV\Desktop\StreamBot\
Loading configuration from file...
Either this is the first time this script is being run, or there was an error reading the config file. You will now be walked through obtaining all the credentials this bot needs in order to function.
We will first get the bot's Reddit information.
Press enter to continue...

My configuration.ini file is still present and exactly the same as it was, besides me going ahead and adding more games and streamers via PMing the Bot, however that's nothing special, intended use. Everything's in the same order, no missing information, etc. Which is actually weird, considering usually if you run the script, exit, delete configuration.ini, and redo setup the order the top credentials are in will actually be changed everytime you run through setup.

I even made a copy of the Python Script from its working state incase this happened, assuming maybe it was modifying itself and breaking something lol. Just tried my backup that was working, no luck, still says something is wrong with my configuration.ini.

kii-chan-reloaded commented 7 years ago

I've made a new Debugging branch. Theoretically, this will attempt to load your file, and will freeze when it fails. I've added more messages for when things fail in the configuration loading process, so hopefully we can pinpoint what's going on here. I'll probably push most of these changes to the master branch once this works out, since more verbosity is usually better.

For what it's worth, I'm not able to recreate your issues on my computer. That's not really saying a whole lot though since I'm on Linux, and two completely different OSes will behave completely differently.

EthanC commented 7 years ago

Awesome! I appreciate you helping me get this resolved :)

Using the code from the Debugging Branch, here's what happens when I launch SidebarStreamers.py with my configuration.ini that worked perfectly fine prior:

Importing praw
Importing re
Importing configparser
Importing time
Importing requests
Importing json
Loading configuration from file...
('G', 'call of duty', 'C:\\Users\\SERV\\Desktop\\StreamBot\\configuration.ini', 18)
Press enter to regenerate the configuration file.

Line 18 of my configuration.ini is as follows: call of duty: advanced warfare = Good

I've also noticed that if a Streamer or Game is added via the Python Script, it gets = true while if you PM the bot it gets = Good, if that's of any significance?

kii-chan-reloaded commented 7 years ago

The Good vs True thing was an oversight an my part and literally means nothing. The bot actually only uses the value names as opposed to what the value actually is for the games and streamer sections. You could put in Ignore this game we do not want it in our sidebar as the value for a game and it would still put it in your sidebar. I fixed that difference in the first debug revision, so it'll hit the master branch once this gets figured out.

My initial guess is that the : is causing configparser to fail to read the file, however when I add that line to my config file, it still loads properly. Regardless, I've pushed a new revision to the Debug branch that will ignore :'s altogether. Download that, then remove all :'s from configuration.ini (i.e. call of duty advanced warfare = Good), save it, and run the bot again. If that works for you, then I'll consider this solved and close the issue.

EthanC commented 7 years ago

Nice, that seems to have fixed it.

Just to be sure, the bot will still add a streamer to the sidebar say for example if their game is call of duty: advanced warfare on Twitch, but configuration.ini only has call of duty advanced warfare, correct?

kii-chan-reloaded commented 7 years ago

That is correct, it will remove the : from the game name when looking at twitch streams. I'm going to add the same behavior for = as well, so check the master branch in about 30 minutes or so. That will also undo the freezing if errors occur.

EthanC commented 7 years ago

Thanks again for the help! I'll be on the lookout for that commit. Also going to open a Feature Request for YouTube Stream Support if that's something you'd be willing to do, feel free to close it however. I'll get out of your hair now :)

EthanC commented 7 years ago

@WolfgangAxel should I open a new issue for this error? This is the error that I referenced above, seems to be happening after extended periods of leaving the script running.

Summit1G is playing Blackwake
Summit1G is playing Blackwake
Summit1G is playing Blackwake
Summit1G is playing Blackwake
Summit1G is playing Blackwake
Summit1G is playing Blackwake
Summit1G is playing Blackwake
Summit1G is playing Blackwake
Error!

('stream',)

Retrying in one minute.
Error!

('Expecting value: line 1 column 1 (char 0)',)

Retrying in one minute.

Happened in both of my seperate instances of the script I had running overnight.

kii-chan-reloaded commented 7 years ago

Let's go ahead and open a new issue. I rewrote the error message to be a little more useful, so get the latest in the Debugging branch. Let it run until it fails again, then give me that output. Also, how many streamers are in your file? I can't find any definitive numbers for what their rate limit is for requests, but maybe it's possible you're hitting that. I found that their IRC has a limit of 20 messages per 30 seconds and you get locked out for 30 minutes, but nothing cut and dry about their regular service. I went ahead and put in a 1 second delay between each streamer status request, which is pretty standard in my limited experience with web APIs. We can probably go down as far as 0.5 seconds if 1 second per streamer is going to be too long.

If the bot lasts for more than a day without errors on that new script, then we'll assume that was the issue and call it closed before we even open it.