Giter Site home page Giter Site logo

Comments (8)

trocotronic avatar trocotronic commented on July 16, 2024

I'd need a full debug log as I cannot reproduce it. It works to me.

BTW try deleting *.access and *.session files.

from edistribucion.

davidcm avatar davidcm commented on July 16, 2024

Thanks for answering!

Yes, already tried deleting access and session files.

I'm able to login from their iOS app, which basically is their website (they say they're under maintenance, although I can access my private area anyway), but I can't login from my laptop directly to their website, no reason given... Maybe due to this maintenance? I don't know. Could I be banned somehow due to too many requests? I've had a script running, getting meter data every 15 minutes for weeks.

Nevertheless, in hopes it's useful given the above current circumstance, here's the full log:

[15/07/2023 23:05:24] [WARNING] Session file not found
[15/07/2023 23:05:24] [WARNING] Access file not found
[15/07/2023 23:05:24] [INFO] Loging
[15/07/2023 23:05:24] [WARNING] Forcing login
[15/07/2023 23:05:25] [INFO] Sending GET request to https://zonaprivada.edistribucion.com/areaprivada/s/login/?language=es&ec=302&startURL=%2Fareaprivada%2Fs%2F
[15/07/2023 23:05:25] [INFO] Response with code: 200
[15/07/2023 23:05:25] [INFO] Loading scripts
[15/07/2023 23:05:25] [INFO] Performing login routine
[15/07/2023 23:05:25] [INFO] Sending POST request to https://zonaprivada.edistribucion.com/areaprivada/s/sfsites/aura?other.LightningLoginForm.login=1
[15/07/2023 23:05:25] [INFO] Response with code: 200
[15/07/2023 23:05:25] [INFO] Accessing to frontdoor
[15/07/2023 23:05:25] [INFO] Sending GET request to https://zonaprivada.edistribucion.com/areaprivada/secur/frontdoor.jsp?allp=1&apv=1&cshc=o000008YGuJ4000000fNRm&refURL=https%3A%2F%2Fzonaprivada.edistribucion.com%2Fareaprivada%2Fsecur%2Ffrontdoor.jsp&retURL=%2Fareaprivada%2Fs%2F&sid=00D24000000fNRm%21AQgAQIZ9TYZFIRL2guH7jijmxcKaZjKZqaMxM8_qd2PX_3IfA7RgDDaMB97zy6UvGeuuT3NVk9jCBNX5g1kD2FRU.g3XqULN&untethered=
[15/07/2023 23:05:25] [INFO] Response with code: 200
[15/07/2023 23:05:25] [INFO] Accessing to landing page
[15/07/2023 23:05:25] [INFO] Sending GET request to https://zonaprivada.edistribucion.com/areaprivada/s/
[15/07/2023 23:05:25] [INFO] Response with code: 200
[15/07/2023 23:05:25] [INFO] Loading token scripts
Traceback (most recent call last):
File "/home/pi/edistribucion/./meter.py", line 29, in
edis = Edistribucion(login, password, logging.INFO)
File "/home/pi/edistribucion/src/EdistribucionAPI/Edistribucion.py", line 133, in init
self.login()
File "/home/pi/edistribucion/src/EdistribucionAPI/Edistribucion.py", line 240, in login
return self.__force_login()
File "/home/pi/edistribucion/src/EdistribucionAPI/Edistribucion.py", line 314, in __force_login
raise EdisError('token not found. Cannot continue')
EdistribucionAPI.Edistribucion.EdisError: token not found. Cannot continue

from edistribucion.

davidcm avatar davidcm commented on July 16, 2024

Sorry for the misunderstanding, I can now login from the website in a browser. It was a cookies issue apparently.

I still can't login from python, though.

Tried looking into the __get_token code.

...
logging.info('Loading token scripts')
    for s in scripts:
        logging.info(s.text)
...

Looks like it's retrieving empty scripts for some reason.

from edistribucion.

davidcm avatar davidcm commented on July 16, 2024

I'm not sure what's going on here... Trying to debug def __get_token(self):

The scripts variable gets populated with the <script ... parts. Even I can see by printing it that one of the parts contains the auraConfig string that it's expecting. But s.text is always empty... And never enters in if ('auraConfig' in s.text): or even in if ('auraConfig' in s):

I'm not super fluent in python, so I don't know what else to look.

from edistribucion.

trocotronic avatar trocotronic commented on July 16, 2024

You mean https://github.com/trocotronic/edistribucion/blob/master/src/EdistribucionAPI/Edistribucion.py#L249?

Try commenting this line (just add a #, #if ('auraConfig' in s.text): and let see if it works.

from edistribucion.

davidcm avatar davidcm commented on July 16, 2024

No luck :(

I have modified the function like this:

    def __get_token(self):
        r = self.__get_url('https://zonaprivada.edistribucion.com/areaprivada/s/')
        soup = BeautifulSoup(r.text, 'html.parser')
        # logging.info(soup)
        scripts = soup.find_all('script')
        logging.info(f'Loading token scripts ({len(scripts)})')
        for s in scripts:
            if 'auraConfig' in str(s):
                logging.info("Found 'auraConfig'")
                logging.info(f"s =\n{str(s)[:300]}")
                logging.info(f"s.text =\n{s.text}")
            if True: #if ('auraConfig' in s.text):
                prsr = jsparse(s.text)
                for b in prsr['body']:
                    decls = b.get('expression', {}).get('callee', {}).get('body', {}).get('body', [])
                    for d in decls:
                        if (d.get('type', None) == 'VariableDeclaration'):
                            for dc in d.get('declarations', []):
                                if (dc.get('id', {}).get('name', None) == 'auraConfig'):
                                    for prop in dc.get('init', {}).get('properties', []):
                                        if (prop.get('key', {}).get('value', None) == 'token'):
                                            return prop.get('value', {}).get('value', None)
        logging.error("Could not find token!")
        return None

And the relevant log that this outputs is:

[21/07/2023 19:02:16] [INFO] Sending GET request to https://zonaprivada.edistribucion.com/areaprivada/s/
[21/07/2023 19:02:16] [INFO] Response with code: 200
[21/07/2023 19:02:16] [INFO] Loading token scripts (11)
[21/07/2023 19:02:16] [INFO] Found 'auraConfig'
[21/07/2023 19:02:16] [INFO] s =
<script nonce="yNmRuC3HJ1L45uF8FmxeYaRnlSVLYX7o">
(function () {
window.pageStartTime = (new Date()).getTime();
window.Aura || (window.Aura = {});
window.Aura.bootstrap || (window.Aura.bootstrap = {});


var time = window.performance && window.performance.now ? window.performance.now.bind(performanc
[21/07/2023 19:02:16] [INFO] s.text =

[21/07/2023 19:02:16] [ERROR] Could not find token!
Traceback (most recent call last):
  File "/home/pi/edistribucion/./meter.py", line 29, in <module>
    edis = Edistribucion(login, password, logging.INFO)
  File "/home/pi/edistribucion/src/EdistribucionAPI/Edistribucion.py", line 133, in __init__
    self.login()
  File "/home/pi/edistribucion/src/EdistribucionAPI/Edistribucion.py", line 240, in login
    return self.__force_login()
  File "/home/pi/edistribucion/src/EdistribucionAPI/Edistribucion.py", line 320, in __force_login
    raise EdisError('token not found. Cannot continue')
EdistribucionAPI.Edistribucion.EdisError: token not found. Cannot continue

from edistribucion.

davidcm avatar davidcm commented on July 16, 2024

Interesting... Found out the .text property returns the texts that is human-visible in the web page, but the script content is not, so .string should be used. I tried it and it works! It finds the token and everything works as before...

Why did it work before and suddenly not? I don't know... Maybe BeautifulSoup got updated in my system without noticing and it broke this script? Pip says I have 4.9.3 installed.

from edistribucion.

trocotronic avatar trocotronic commented on July 16, 2024

from edistribucion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.