32
32
import random
33
33
import string
34
34
35
- import captchasolver
35
+ import recaptchasolver
36
36
37
37
38
38
_LOGGER = logging .getLogger (__name__ )
@@ -59,7 +59,7 @@ def main(emailItem, passwordItem):
59
59
60
60
attempts = 0
61
61
tpw = powerwall_site (gateway_host , password , email )
62
- while 'fail' in tpw .token and attempts < 6 :
62
+ while 'fail' in tpw .token and attempts < 5 :
63
63
print ("attempts count: " , attempts )
64
64
try :
65
65
attempts = attempts + 1
@@ -143,19 +143,22 @@ def authenticate(self):
143
143
print "authenticate method"
144
144
auth_url = self .authUrl ();
145
145
146
- headers = {
147
- 'User-Agent' : 'PowerwallDarwinManager'
148
- }
149
- # headers = {}
146
+ # headers = {
147
+ # # 'User-Agent' : 'PowerwallDarwinManager'
148
+ # }
149
+ headers = {}
150
150
resp = session .get (auth_url , headers = headers )
151
+ #print (resp.text)
151
152
152
- csrf = re .search (r'name="_csrf".+value="([^"]+)"' , resp .text ).group (1 )
153
- transaction_id = re .search (r'name="transaction_id".+value="([^"]+)"' , resp .text ).group (1 )
154
153
154
+ recaptcha_site_key = re .search (r".*sitekey.* : '(.*)'" , resp .text ).group (1 )
155
+ print ('captcha sitekey: ' + recaptcha_site_key )
156
+ print ('auth url: ' + auth_url )
155
157
156
158
157
- captchacode = captchasolver .main (session , headers )
158
- print ("captchacode: " , captchacode )
159
+ csrf = re .search (r'name="_csrf".+value="([^"]+)"' , resp .text ).group (1 )
160
+ transaction_id = re .search (r'name="transaction_id".+value="([^"]+)"' , resp .text ).group (1 )
161
+ captchacode = recaptchasolver .main (recaptcha_site_key , auth_url )
159
162
160
163
data = {
161
164
"_csrf" : csrf ,
@@ -165,8 +168,11 @@ def authenticate(self):
165
168
"cancel" : "" ,
166
169
"identity" : self .email ,
167
170
"credential" : self .password ,
168
- "captcha" : captchacode
171
+ "g-recaptcha-response:" : captchacode ,
172
+ "recaptcha" : captchacode
169
173
}
174
+
175
+ #print(data)
170
176
print "Opening session with login"
171
177
# Important to say redirects false cause this will result in 302 and need to see next data
172
178
resp = session .post (auth_url , headers = headers , data = data , allow_redirects = False )
@@ -253,7 +259,14 @@ def authenticate(self):
253
259
254
260
# If not MFA This code plays instead , which is parising location
255
261
print "Coming to non MFA flow:"
262
+ #print (resp)
263
+ #print ("response text: ==================================")
264
+ #print (resp.text)
265
+ #print ("response headers: ----------------------------------------")
266
+ #print (resp.headers)
267
+
256
268
code_url = resp .headers ["location" ]
269
+ print ("location header: " + str (code_url ))
257
270
parsed = urlparse .urlparse (code_url )
258
271
code = urlparse .parse_qs (parsed .query )['code' ]
259
272
0 commit comments