I swear this was working in OctoPrint 1.3.11 and earlier. A local request to the REST API seems to now be freezing up within a plugin.
Before:
I didn't have the data=
in the second argument to requests.put. I was also doing all this in Py2.
After
Now I'm in Py3 and 1.4.rc3. Having researched a little, I'm guessing that the newer requests
module wants that data=
prepended to the second argument.
def __set_user_password(apiKey, username, password):
if apiKey == op.octoprintApiKey:
op.logger.debug('__set_user_password calling REST API [' + username + '][' + password + ']')
api_url = op.octoprintBaseUrl + '/api/users/' + username + '/password'
op.logger.debug('__set_user_password [' + api_url + ']')
op.logger.debug('__set_user_password [' + apiKey + ']')
jsonBody = json.dumps({"password":str(password)})
op.logger.debug('__set_user_password [' + str(jsonBody) + ']')
r = requests.put(api_url, data=jsonBody, headers={"X-Api-Key":apiKey,"Content-Type":"application/json"})
self.logger.debug('__set_user_password api returned ' + str(r.status_code))
if r.status_code == 200:
del r
return True
del r
return False
Simply trying to set my password to password
yields (in my log):
[DEBUG] __set_user_password calling REST API [me][password]
[DEBUG] __set_user_password [http://localhost/api/users/me/password]
[DEBUG] __set_user_password [CORRECT-API-KEY]
[DEBUG] __set_user_password [{"password": "password"}]
---- Freeze-up ------------------------------------------------------------------------------------------------
I do the same with Postman and of course it returns immediately from that software. I note that the REST API is called, OctoPrint does make the update to the indicated password. The timestamp on the ~/.octoprint/users.yaml
matches the attempt's time. The MD5 hash is correctly stored for the password
change in this file.