MrInka Posted April 20, 2017 Report Posted April 20, 2017 (edited) Hey, I see that there are already topics discussing this particular error, but most of them aren't including code examples. Tried to fix it myself, but it doesn't seem to work. So when accepting an offer, I sometimes get this error: Error: Not Logged In at SteamCommunity._checkCommunityError (/home/pi/Desktop/bot_final/node_modules/steamcommunity/components/http.js:128:9) at Request._callback (/home/pi/Desktop/bot_final/node_modules/steamcommunity/components/http.js:51:88) at Request.self.callback (/home/pi/Desktop/bot_final/node_modules/steamcommunity/node_modules/request/request.js:186:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request.<anonymous> (/home/pi/Desktop/bot_final/node_modules/steamcommunity/node_modules/request/request.js:1081:10) at emitOne (events.js:96:13) at Request.emit (events.js:188:7) at Gunzip.<anonymous> (/home/pi/Desktop/bot_final/node_modules/steamcommunity/node_modules/request/request.js:1001:12) at Gunzip.g (events.js:291:16)So to log in, I am using this: var config = require('./config.js'); var SteamCommunity = require('steamcommunity'); var SteamTotp = require('steam-totp'); var SteamUser = require('steam-user'); var TradeOfferManager = require('steam-tradeoffer-manager'); var community = new SteamCommunity(); var client = new SteamUser(); var manager = new TradeOfferManager({ steam: client, domain: 'example.com', language: 'en' }); client.logOn({ accountName: config.username, password: config.password, twoFactorCode: SteamTotp.generateAuthCode(config.sharedsecret) }); client.on('loggedOn', function(details) { console.log("Bot logged in"); client.setPersona(SteamUser.Steam.EPersonaState.Online,config.botname); }); client.on('webSession', function(sessionID, cookies) { manager.setCookies(cookies, function(err) { if (err) return console.log(err); console.log(" > Got API key!"); }); community.setCookies(cookies); community.startConfirmationChecker(10000, config.identitysecret); })And to keep the bot from coming up with the "Not logged in error", I added this (which obviously doesnt work). var lastLoginAttempt = Date.now(); client.on("sessionExpired", function(err) { if(Date.now() - lastLoginAttempt > 30000) { lastLoginAttempt = Date.now(); console.log(" > Session Expired, relogging."); client.webLogOn(); } else { console.log(" Session Expired, waiting a while before attempting to relogin."); } });I was told to add a "timer" so it doesn't spam the login when the websession expires. Any idea why it doesn't work? Is client.webLogOn() the right way to log in again? Any help is appreciated! Edited April 20, 2017 by MrInka Quote
Dr. McKay Posted April 20, 2017 Report Posted April 20, 2017 Yes, client.webLogOn is the correct way to do it. I suspect that you're getting a new web session successfully (add some logging to the webSession event to make sure), and you're just doing something else wrong. Quote
DevDuck Posted May 1, 2017 Report Posted May 1, 2017 (edited) Yes, client.webLogOn is the correct way to do it. I suspect that you're getting a new web session successfully (add some logging to the webSession event to make sure), and you're just doing something else wrong. sessionExpired event is not a module node-steamcommunity? client.on('sessionExpired') or community.on('sessionExpired')? I have similar code: community.on('sessionExpired', (err) => { });But I get a error after a couple days of work of the bot: Error: Not Logged InBut the event community.on('sessionExpired') is not triggered. Maybe need to catch event client.on('sessionExpired')? Edited May 1, 2017 by DevDuck Quote
SunriseM Posted May 1, 2017 Report Posted May 1, 2017 (edited) sessionExpired event is not a module node-steamcommunity? client.on('sessionExpired') or community.on('sessionExpired')? Yes its in the community module. What do you have exactly inside of community.on('sessionExpired', (err) => { }); Edited May 1, 2017 by SunriseM Quote
DevDuck Posted May 1, 2017 Report Posted May 1, 2017 (edited) this.community.on('sessionExpired', (err) => { console.log('sessionExpired. ', + err); this.client.webLogOn(); });But in the logs I don't see errors (sessionExpired. + err)... based on this the event is not triggered. Update. I tried this: setTimeout(() => { this.community.setCookies(['steamLogin=invalid', 'steamLoginSecure=invalid']); }, 30000);but the event sessionExpired anyway is not triggered Edited May 1, 2017 by DevDuck Quote
Dr. McKay Posted May 1, 2017 Report Posted May 1, 2017 Pass the community instance in to the constructor of TradeOfferManager, as per the docs. Quote
DevDuck Posted May 1, 2017 Report Posted May 1, 2017 Pass the community instance in to the constructor of TradeOfferManager, as per the docs. Thank you! And one more question: this event (sessionExpired) will be emitted when be done some error? Or this event is the interval? Quote
SunriseM Posted May 2, 2017 Report Posted May 2, 2017 (edited) Pass the community instance in to the constructor of TradeOfferManager, as per the docs. I tested with this code: self.community.on('sessionExpired', (err) => { log.info("Session Expired"); }); setTimeout(function(){ log.info("Killing Cookies"); self.community.setCookies(["steamLogin=1||invalid", "steamLoginSecure=1||invalid"]); }, 31000); setTimeout(function(){ log.info("Fixing Cookies"); self.client.webLogOn(); },60000); setInterval(function(){ self.community.getNotifications(function(err, notifications){ if(err) log.error(err); else log.info(notifications); }); }, 15000); After the Killing Cookies part. getNotifications returns HTTP Error 401 (Not authorized), after the Fixing Cookies part i get the notifications without errors. Then i checked the source code and found out that you only emit "sessionExpired" when HTTP Error is from 300 to 399. When its 401 it just callbacks the error. if (response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) { err = new Error("Not Logged In"); callback(err, response, body); this._notifySessionExpired(err); return err; } Edit: i found this part too. but for some reason im not getting the sessionExpired event. if (typeof html === 'string' && html.match(/g_steamID = false;/) && html.match(/<h1>Sign In<\/h1>/)) { err = new Error("Not Logged In"); callback(err); this._notifySessionExpired(err); return err; } Edit 2: Modified this part and it worked, but i suppose it needs more changes. if (response.statusCode >= 400) { err = new Error("HTTP error " + response.statusCode); err.code = response.statusCode; callback(err, response, body); this._notifySessionExpired(err); // <----- return err; } Edited May 2, 2017 by SunriseM Quote
Dr. McKay Posted May 2, 2017 Report Posted May 2, 2017 "status code >= 400" is inappropriate for detecting if the session has expired. Using that, you'll end up relogging constantly if you end up getting rate-limited (403 or 429), for example. Quote
SunriseM Posted May 2, 2017 Report Posted May 2, 2017 "status code >= 400" is inappropriate for detecting if the session has expired. Using that, you'll end up relogging constantly if you end up getting rate-limited (403 or 429), for example.Yes i know that you didn't put that there for some reason. But what if we check only for status code === 401? Quote
Dr. McKay Posted May 2, 2017 Report Posted May 2, 2017 That should probably be fine, although I don't know for sure that Steam would give 401 for only logged-out errors. Steam is weird. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.