Accessing via websocket from Python

As described in this post in the Printer specific Forum of my printer i try to login to repetier server via Websocket from my raspberry pi with python.



When i delete all users and pw, it works, but i cannot figure out the right syntax for the login sending

Could someone provide a Python code Example how either the login with apikey ord with login credentials should look like? Am i doing the MD5 calclulation wrong?

Or does something need to be url encoded?

Not to get me wrong, i don't want to connect via ther browser address bar, i want to connect headlas from within a python script.


Help would be very appreciated

Comments

  • Since you are building md5 of md5 it is important if the hex digits are uppercase or lowercase. Not sure which one is correct, you might check communication with web frontend in chrome. There you can inspect the frame packages to see if it uses lower or upper case. Apart from this a first look seems correct. You can always compare to the api example which is a minimal javascript example which you could add some console.log outputs to for comparing.
  • edited January 8
    mm i Tried with uppercasing and in lowercase, no luck, there must be somewhere a little think issue:

    here my code maybe someone has a clue:

            c = ws.send("""{"action":"ping","data":{},"printer":"MyPrinter","callback_id":""" + str(drucker_befehl_id) + "}")
            result =  ws.recv()
            print(str(result))
            if "session" in (result):
                sessionidtemp = (result.split("\"session\":",1)[1])
                sessionid = sessionidtemp[:-1]
                print(sessionid)
            else:
                pass

            #userlogout=ws.send('{"action":logout","dara":{},"printer":"MyPrinter","callback_id":""" + str(drucker_befehl_id) + "}"')
     
            bn="benutzername"
            pw="password"
            md5bnpwgesamt=(hashlib.md5((bn+pw).encode('utf-8')).hexdigest())
            md5bnpwgesamt=md5bnpwgesamt.upper()
            print("bnpwgesamtupper =     ", md5bnpwgesamt)
            sessionid = sessionid.upper()
            md5combined=(hashlib.md5((sessionid+md5bnpwgesamt).encode('utf-8')).hexdigest())
            md5combined=md5combined.upper()
            print("md5combineduppercase:     " + md5combined)
            print(type(md5combined))
            md5final = '"'+md5combined+'"'
            print("md5final" + md5final)
            a = ('{"action": "login", "callback_id":' + str(drucker_befehl_id) + """, "data": {"login":"benutzername", "password":""" + md5final +'}}')


Sign In or Register to comment.