mcolyer / smartermeter

A ruby library to access PG&E SmartMeter data
http://matt.colyer.name/projects/smartermeter/
MIT License
48 stars 15 forks source link

Change the login URL and login form selection criteria #12

Closed kruton closed 13 years ago

kruton commented 13 years ago

For some reason the login stopped working for me, but changing it to this seems to have fixed it.

mcolyer commented 13 years ago

It looks like the original code is working now (as the maintenance page is gone).

Can you verify that this change still works? If it does I'll go ahead and merge it as it would be more robust.

luckyspin commented 13 years ago

This is still not working for me. I get the following error:

I, [2011-04-25T09:02:02.214988 #83978] INFO -- : Attempting to fetch data for: 2011-04-24 I, [2011-04-25T09:02:02.215137 #83978] INFO -- : Logging in as XXXXXXXX E, [2011-04-25T09:02:03.502308 #83978] ERROR -- : Login failed. E, [2011-04-25T09:02:03.502412 #83978] ERROR -- : #<Mechanize::Page {url

<URI::HTTPS:0x101501b88 URL:https://www.pge.com/eum/login?TYPE=100663297&REALMOID=06-c7dc8818-f1eb-1034-94b0-8304711d0cb3&GUID=&SMAUTHREASON=0&METHOD=GET&SMAGENTNAME=www.pge.com&TARGET=-SM-HTTPS%3a%2f%2fwww%2epge%2ecom%2fcsol%2factions%2flogin%2edo%3faw>}

{meta} {title "PG&E | Login"} {iframes} {frames} {links

<Mechanize::Page::Link "Skip to Main Content" "#main-content">

<Mechanize::Page::Link "user name" "/eum/forgotUserName">

<Mechanize::Page::Link "password" "/eum/forgotPassword">

<Mechanize::Page::Link "Register here." "/eum/registration">

<Mechanize::Page::Link "Need assistance?" "mailto:Authentication@pge.com">}

{forms

<Mechanize::Form

{name "login"} {method "POST"} {action "/eum/login"} {fields

<Mechanize::Form::Text:0x1011a4710

 @name="USER",
 @node=
  #(Element:0x808d4430 {
    name = "input",
    attributes = [
      #(Attr:0x808bb534 { name = "type", value = "text" }),
      #(Attr:0x808bb494 { name = "class", value = "text" }),
      #(Attr:0x808bb318 { name = "id", value = "username" }),
      #(Attr:0x808bb250 { name = "name", value = "USER" })]
    }),
 @value="">
#<Mechanize::Form::Field:0x1011a2050
 @name="PASSWORD",
 @node=
  #(Element:0x808d43a4 {
    name = "input",
    attributes = [
      #(Attr:0x8089d778 { name = "type", value = "password" }),
      #(Attr:0x8089d764 { name = "class", value = "text" }),
      #(Attr:0x8089d73c { name = "id", value = "password" }),
      #(Attr:0x8089d728 { name = "name", value = "PASSWORD" })]
    }),
 @value="">}

{radiobuttons} {checkboxes} {file_uploads} {buttons

<Mechanize::Form::Submit:0x1011a1498

 @name=nil,
 @node=
  #(Element:0x808d21d0 {
    name = "input",
    attributes = [
      #(Attr:0x80878a2c { name = "type", value = "submit" }),
      #(Attr:0x80878a18 { name = "value", value = "Submit" }),
      #(Attr:0x80878a04 {
        name = "onclick",
        value = "javascript:if (!inputValidate()) {return false;}"
        }),
      #(Attr:0x808789dc {
        name = "class",
        value = "move-forward btn-login"
        })]
    }),
 @value="Submit">}>}>

E, [2011-04-25T09:02:03.511066 #83978] ERROR -- : If this happens repeatedly your login information may be incorrect E, [2011-04-25T09:02:03.511122 #83978] ERROR -- : Remove ~/.smartermeter and restart to re-configure smartermeter. I, [2011-04-25T09:02:03.511164 #83978] INFO -- : Successfully fetched:

kruton commented 13 years ago

Yes, it still works. It basically imitates clicking on the "Log-In" link on the main pge.com webpage.

The only problem one might run into is that the login form does not come up if you are already logged in, but I think the old way has that problem as well.

kruton commented 13 years ago

luckyspin, are you using the commit from this pull request? Also, did your log in work before?

luckyspin commented 13 years ago

I was not using the commit from this pull, just the default version in 0.3.3. I had reported it in #11 and that got closed in favor if this issue.

And yes, my login was working before a few days ago.

kruton commented 13 years ago

Try pulling the commit from this issue and see if it fixes the problem.

mcolyer commented 13 years ago

I am just going to include your change as it works in both cases. @kruton Thanks for digging into that!

luckyspin commented 13 years ago

I pulled the commit and now I have a different error:

E, [2011-04-30T16:54:40.575374 #14278] ERROR -- : undefined method USER=' for nil:NilClass (NoMethodError) /Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/lib/smartermeter/service.rb:36:inlogin' (eval):12:in form_with' /Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/lib/smartermeter/service.rb:35:inlogin' /Library/Ruby/Gems/1.8/gems/mechanize-1.0.0/lib/mechanize.rb:262:in get' /Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/lib/smartermeter/service.rb:34:inlogin' /Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/lib/smartermeter/daemon.rb:145:in service' /Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/lib/smartermeter/daemon.rb:166:inconnect' /Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/lib/smartermeter/daemon.rb:178:in fetch_dates' /Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/lib/smartermeter/daemon.rb:126:inrun' /Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/lib/smartermeter/daemon.rb:19:in start' /Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/bin/smartermeter:11 /usr/bin/smartermeter:19:inload' /usr/bin/smartermeter:19 E, [2011-04-30T16:54:40.575529 #14278] ERROR -- : If this happens repeatedly your login information may be incorrect E, [2011-04-30T16:54:40.575566 #14278] ERROR -- : Remove ~/.smartermeter and restart to re-configure smartermeter. I, [2011-04-30T16:54:40.575611 #14278] INFO -- : Successfully fetched: ^C/Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/lib/smartermeter/daemon.rb:131:in sleep': Interrupt from /Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/lib/smartermeter/daemon.rb:131:inrun' from /Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/lib/smartermeter/daemon.rb:19:in start' from /Library/Ruby/Gems/1.8/gems/smartermeter-0.3.3/bin/smartermeter:11 from /usr/bin/smartermeter:19:inload' from /usr/bin/smartermeter:19

Any insight into what is causing this?

mcolyer commented 13 years ago

Are you sure you're using the latest master? It looks like you are using the v0.3.3 release according to the backtrace (which doesn't contain this change). That said, it should still work as that's the version I'm currently running.

However the error seems to indicate that SmarterMeter can't find the login form.

Try visiting http://www.pge.com/myhome/ and verify that the login form element action equals https://www.pge.com/eum/login.