def sign_in(server, username, password, site=""):
"""
Signs in to the server specified with the given credentials
'server' specified server address
'name' is the name (not ID) of the user to sign in as.
Note that most of the functions in this example require that the user
have server administrator permissions.
'password' is the password for the user.
'site' is the ID (as a string) of the site on the server to sign in to. The
default is "", which signs in to the default site.
Returns the authentication token and the site ID.
"""
url = server + "/api/{0}/auth/signin".format(VERSION)
# Builds the request
xml_request = ET.Element('tsRequest')
credentials_element = ET.SubElement(xml_request, 'credentials', name=username, password=password)
ET.SubElement(credentials_element, 'site', contentUrl=site)
xml_request = ET.tostring(xml_request)
# Make the request to server
server_response = requests.post(url, data=xml_request)
_check_status(server_response, 200)
# ASCII encode server response to enable displaying to console
server_response = _encode_for_display(server_response.text)
# Reads and parses the response
parsed_response = ET.fromstring(server_response)
# Gets the auth token and site ID
token = parsed_response.find('t:credentials', namespaces=xmlns).get('token')
site_id = parsed_response.find('.//t:site', namespaces=xmlns).get('id')
user_id = parsed_response.find('.//t:user', namespaces=xmlns).get('id')
return token, site_id, user_id
move_workbook_projects.py 文件源码
python
阅读 14
收藏 0
点赞 0
评论 0
评论列表
文章目录