Also, I think this needs to show up after the line a couple lines down which actually sets the new security context `dxpy.set_security_context(json.loads(sec_context))`.  Otherwise, it will use whatever your previous authentication is to cache the result rather than the new one.