Python API¶
HTTP¶
-
class
RPA.HTTP.
HTTP
(*args, **kwargs)¶ Bases:
RequestsLibrary.RequestsLibrary
RPA Framework HTTP library that extends functionality of RequestsLibrary, for more information see: https://github.com/MarketSquare/robotframework-requests
-
DEFAULT_RETRY_METHOD_LIST
= ['OPTIONS', 'PUT', 'TRACE', 'GET', 'HEAD', 'DELETE']¶
-
ROBOT_LIBRARY_DOC_FORMAT
= 'ROBOT'¶
-
ROBOT_LIBRARY_SCOPE
= 'GLOBAL'¶
-
create_client_cert_session
(alias, url, headers={}, cookies={}, client_certs=None, timeout=None, proxies=None, verify=False, debug=0, max_retries=3, backoff_factor=0.1, disable_warnings=0, retry_status_list=[], retry_method_list=['OPTIONS', 'PUT', 'TRACE', 'GET', 'HEAD', 'DELETE'])¶ Create Session: create a HTTP session to a server
url
Base url of the serveralias
Robot Framework alias to identify the sessionheaders
Dictionary of default headerscookies
Dictionary of cookiesclient_certs
[‘client certificate’, ‘client key’] PEM files containing the client key and certificatetimeout
Connection timeoutproxies
Dictionary that contains proxy urls for HTTP and HTTPS communicationverify
Whether the SSL cert will be verified. A CA_BUNDLE path can also be provided.Defaults to False.
debug
Enable http verbosity option more informationhttps://docs.python.org/2/library/httplib.html#httplib.HTTPConnection.set_debuglevel
max_retries
Number of maximum retries each connection should attempt.By default it will retry 3 times in case of connection errors only. A 0 value will disable any kind of retries regardless of other retry settings. In case the number of retries is reached a retry exception is raised.
disable_warnings
Disable requests warning useful when you have large number of testcasesbackoff_factor
Introduces a delay time between retries that is longer after each retry.eg. if backoff_factor is set to 0.1 the sleep between attemps will be: 0.0, 0.2, 0.4 More info here: https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html
retry_method_list
List of uppercased HTTP method verbs where retries are allowed.By default retries are allowed only on HTTP requests methods that are considered to be idempotent (multiple requests with the same parameters end with the same state). eg. set to [‘POST’, ‘GET’] to retry only those kind of requests.
retry_status_list
List of integer HTTP status codes that, if returned, a retry is attempted.eg. set to [502, 503] to retry requests if those status are returned. Note that max_retries must be greater than 0.
-
create_custom_session
(alias, url, auth, headers={}, cookies={}, timeout=None, proxies=None, verify=False, debug=0, max_retries=3, backoff_factor=0.1, disable_warnings=0, retry_status_list=[], retry_method_list=['OPTIONS', 'PUT', 'TRACE', 'GET', 'HEAD', 'DELETE'])¶ Create Session: create a HTTP session to a server
url
Base url of the serveralias
Robot Framework alias to identify the sessionheaders
Dictionary of default headerscookies
Dictionary of cookiesauth
A Custom Authentication object to be passed on to the requests library.http://docs.python-requests.org/en/master/user/advanced/#custom-authentication
timeout
Connection timeoutproxies
Dictionary that contains proxy urls for HTTP and HTTPS communicationverify
Whether the SSL cert will be verified. A CA_BUNDLE path can also be provided.Defaults to False.
debug
Enable http verbosity option more informationhttps://docs.python.org/2/library/httplib.html#httplib.HTTPConnection.set_debuglevel
max_retries
Number of maximum retries each connection should attempt.By default it will retry 3 times in case of connection errors only. A 0 value will disable any kind of retries regardless of other retry settings. In case the number of retries is reached a retry exception is raised.
disable_warnings
Disable requests warning useful when you have large number of testcasesbackoff_factor
Introduces a delay time between retries that is longer after each retry.eg. if backoff_factor is set to 0.1 the sleep between attemps will be: 0.0, 0.2, 0.4 More info here: https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html
retry_method_list
List of uppercased HTTP method verbs where retries are allowed.By default retries are allowed only on HTTP requests methods that are considered to be idempotent (multiple requests with the same parameters end with the same state). eg. set to [‘POST’, ‘GET’] to retry only those kind of requests.
retry_status_list
List of integer HTTP status codes that, if returned, a retry is attempted.eg. set to [502, 503] to retry requests if those status are returned. Note that max_retries must be greater than 0.
-
create_digest_session
(alias, url, auth, headers={}, cookies={}, timeout=None, proxies=None, verify=False, debug=0, max_retries=3, backoff_factor=0.1, disable_warnings=0, retry_status_list=[], retry_method_list=['OPTIONS', 'PUT', 'TRACE', 'GET', 'HEAD', 'DELETE'])¶ Create Session: create a HTTP session to a server
url
Base url of the serveralias
Robot Framework alias to identify the sessionheaders
Dictionary of default headerscookies
Dictionary of cookiesauth
[‘DOMAIN’, ‘username’, ‘password’] for NTLM Authenticationtimeout
Connection timeoutproxies
Dictionary that contains proxy urls for HTTP and HTTPS communicationverify
Whether the SSL cert will be verified. A CA_BUNDLE path can also be provided.Defaults to False.
debug
Enable http verbosity option more informationhttps://docs.python.org/2/library/httplib.html#httplib.HTTPConnection.set_debuglevel
max_retries
Number of maximum retries each connection should attempt.By default it will retry 3 times in case of connection errors only. A 0 value will disable any kind of retries regardless of other retry settings. In case the number of retries is reached a retry exception is raised.
disable_warnings
Disable requests warning useful when you have large number of testcasesbackoff_factor
Introduces a delay time between retries that is longer after each retry.eg. if backoff_factor is set to 0.1 the sleep between attemps will be: 0.0, 0.2, 0.4 More info here: https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html
retry_method_list
List of uppercased HTTP method verbs where retries are allowed.By default retries are allowed only on HTTP requests methods that are considered to be idempotent (multiple requests with the same parameters end with the same state). eg. set to [‘POST’, ‘GET’] to retry only those kind of requests.
retry_status_list
List of integer HTTP status codes that, if returned, a retry is attempted.eg. set to [502, 503] to retry requests if those status are returned. Note that max_retries must be greater than 0.
-
create_ntlm_session
(alias, url, auth, headers={}, cookies={}, timeout=None, proxies=None, verify=False, debug=0, max_retries=3, backoff_factor=0.1, disable_warnings=0, retry_status_list=[], retry_method_list=['OPTIONS', 'PUT', 'TRACE', 'GET', 'HEAD', 'DELETE'])¶ Create Session: create a HTTP session to a server
url
Base url of the serveralias
Robot Framework alias to identify the sessionheaders
Dictionary of default headerscookies
Dictionary of cookiesauth
[‘DOMAIN’, ‘username’, ‘password’] for NTLM Authenticationtimeout
Connection timeoutproxies
Dictionary that contains proxy urls for HTTP and HTTPS communicationverify
Whether the SSL cert will be verified. A CA_BUNDLE path can also be provided.Defaults to False.
debug
Enable http verbosity option more informationhttps://docs.python.org/2/library/httplib.html#httplib.HTTPConnection.set_debuglevel
max_retries
Number of maximum retries each connection should attempt.By default it will retry 3 times in case of connection errors only. A 0 value will disable any kind of retries regardless of other retry settings. In case the number of retries is reached a retry exception is raised.
disable_warnings
Disable requests warning useful when you have large number of testcasesbackoff_factor
Introduces a delay time between retries that is longer after each retry.eg. if backoff_factor is set to 0.1 the sleep between attemps will be: 0.0, 0.2, 0.4 More info here: https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html
retry_method_list
List of uppercased HTTP method verbs where retries are allowed.By default retries are allowed only on HTTP requests methods that are considered to be idempotent (multiple requests with the same parameters end with the same state). eg. set to [‘POST’, ‘GET’] to retry only those kind of requests.
retry_status_list
List of integer HTTP status codes that, if returned, a retry is attempted.eg. set to [502, 503] to retry requests if those status are returned. Note that max_retries must be greater than 0.
-
create_session
(alias, url, headers={}, cookies={}, auth=None, timeout=None, proxies=None, verify=False, debug=0, max_retries=3, backoff_factor=0.1, disable_warnings=0, retry_status_list=[], retry_method_list=['OPTIONS', 'PUT', 'TRACE', 'GET', 'HEAD', 'DELETE'])¶ Create Session: create a HTTP session to a server
alias
Robot Framework alias to identify the sessionurl
Base url of the serverheaders
Dictionary of default headerscookies
Dictionary of cookiesauth
List of username & password for HTTP Basic Authtimeout
Connection timeoutproxies
Dictionary that contains proxy urls for HTTP and HTTPS communicationverify
Whether the SSL cert will be verified. A CA_BUNDLE path can also be provided.debug
Enable http verbosity option more informationhttps://docs.python.org/2/library/httplib.html#httplib.HTTPConnection.set_debuglevel
max_retries
Number of maximum retries each connection should attempt.By default it will retry 3 times in case of connection errors only. A 0 value will disable any kind of retries regardless of other retry settings. In case the number of retries is reached a retry exception is raised.
disable_warnings
Disable requests warning useful when you have large number of testcasesbackoff_factor
Introduces a delay time between retries that is longer after each retry.eg. if backoff_factor is set to 0.1 the sleep between attemps will be: 0.0, 0.2, 0.4 More info here: https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html
retry_method_list
List of uppercased HTTP method verbs where retries are allowed.By default retries are allowed only on HTTP requests methods that are considered to be idempotent (multiple requests with the same parameters end with the same state). eg. set to [‘POST’, ‘GET’] to retry only those kind of requests.
retry_status_list
List of integer HTTP status codes that, if returned, a retry is attempted.eg. set to [502, 503] to retry requests if those status are returned. Note that max_retries must be greater than 0.
-
delete_all_sessions
()¶ Removes all the session objects
-
delete_request
(alias, uri, data=None, json=None, params=None, headers=None, allow_redirects=None, timeout=None)¶ Send a DELETE request on the session object found using the given alias
alias
that will be used to identify the Session object in the cacheuri
to send the DELETE request tojson
a value that will be json encodedand sent as request data if data is not specified
headers
a dictionary of headers to use with the requestallow_redirects
Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.timeout
connection timeout
-
download
(url: str, target_file: str = None, binary: bool = True, verify: bool = True, force_new_session: bool = False, overwrite: bool = False) → dict¶ An alias for the
HTTP Get
keyword.The difference in use is that the URL is always downloaded based on the URL path (even without
target_file
). If there is a filename in the path, then that is used astarget_file
to save to. By default, the filename will be “downloaded.html”.url
target URL for GET requesttarget_file
filepath to save request content, defaultNone
binary
if file is saved as binary, defaultTrue
verify
if SSL verification should be done, defaultTrue
force_new_session
if new HTTP session should be created, defaultFalse
overwrite
used together withtarget_file
, ifTrue
will overwrite the target file, defaultFalse
-
get_current_session_alias
() → str¶ Get request session alias that was used with the
HTTP Get
keyword.Return name of session alias.
-
static
get_file_for_streaming_upload
(path)¶ Opens and returns a file descriptor of a specified file to be passed as
data
parameter to other requests keywords.This allows streaming upload of large files without reading them into memory.
File descriptor is binary mode and read only. Requests keywords will automatically close the file, if used outside this library it’s up to the caller to close it.
-
get_request
(alias, uri, headers=None, data=None, json=None, params=None, allow_redirects=None, timeout=None)¶ Send a GET request on the session object found using the given alias
alias
that will be used to identify the Session object in the cacheuri
to send the GET request toparams
url parameters to append to the uriheaders
a dictionary of headers to use with the requestdata
a dictionary of key-value pairs that will be urlencodedand sent as GET data or binary data that is sent as the raw body content
json
a value that will be json encodedand sent as GET data if data is not specified
allow_redirects
Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.timeout
connection timeout
-
head_request
(alias, uri, headers=None, allow_redirects=None, timeout=None)¶ Send a HEAD request on the session object found using the given alias
alias
that will be used to identify the Session object in the cacheuri
to send the HEAD request toallow_redirects
Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.headers
a dictionary of headers to use with the requesttimeout
connection timeout
-
http_get
(url: str, target_file: str = None, binary: bool = True, verify: bool = True, force_new_session: bool = False, overwrite: bool = False) → dict¶ A helper method for
Get Request
that will create a session, perform GET request, and store the target file, if set by thetarget_file
parameter.The old session will be used if the URL scheme and the host are the same as previously, e.g., ‘https://www.google.fi’ part of the URL.
url
target URL for GET requesttarget_file
filepath to save request content, defaultNone
binary
if file is saved as binary, defaultTrue
verify
if SSL verification should be done, defaultTrue
force_new_session
if new HTTP session should be created, defaultFalse
overwrite
used together withtarget_file
, ifTrue
will overwrite the target file, defaultFalse
Returns request response.
-
options_request
(alias, uri, headers=None, allow_redirects=None, timeout=None)¶ Send an OPTIONS request on the session object found using the given alias
alias
that will be used to identify the Session object in the cacheuri
to send the OPTIONS request toallow_redirects
Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.headers
a dictionary of headers to use with the requesttimeout
connection timeout
-
patch_request
(alias, uri, data=None, json=None, params=None, headers=None, files=None, allow_redirects=None, timeout=None)¶ Send a PATCH request on the session object found using the given alias
alias
that will be used to identify the Session object in the cacheuri
to send the PATCH request todata
a dictionary of key-value pairs that will be urlencodedand sent as PATCH data or binary data that is sent as the raw body content or file descriptor retrieved by Get File For Streaming Upload
json
a value that will be json encodedand sent as PATCH data if data is not specified
headers
a dictionary of headers to use with the requestfiles
a dictionary of file names containing file data to PATCH to the serverallow_redirects
Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.params
url parameters to append to the uritimeout
connection timeout
-
post_request
(alias, uri, data=None, json=None, params=None, headers=None, files=None, allow_redirects=None, timeout=None)¶ Send a POST request on the session object found using the given alias
alias
that will be used to identify the Session object in the cacheuri
to send the POST request todata
a dictionary of key-value pairs that will be urlencodedand sent as POST data or binary data that is sent as the raw body content or passed as such for multipart form data if
files
is also defined or file descriptor retrieved by Get File For Streaming Uploadjson
a value that will be json encodedand sent as POST data if files or data is not specified
params
url parameters to append to the uriheaders
a dictionary of headers to use with the requestfiles
a dictionary of file names containing file data to POST to the serverallow_redirects
Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.timeout
connection timeout
-
put_request
(alias, uri, data=None, json=None, params=None, files=None, headers=None, allow_redirects=None, timeout=None)¶ Send a PUT request on the session object found using the given alias
alias
that will be used to identify the Session object in the cacheuri
to send the PUT request todata
a dictionary of key-value pairs that will be urlencodedand sent as PUT data or binary data that is sent as the raw body content or file descriptor retrieved by Get File For Streaming Upload
json
a value that will be json encodedand sent as PUT data if data is not specified
headers
a dictionary of headers to use with the requestallow_redirects
Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.params
url parameters to append to the uritimeout
connection timeout
-
request_should_be_successful
(response)¶ Fails if response status code is a client or server error (4xx, 5xx).
The
response
is the output of other requests keywords likeGet Request
.In case of failure an HTTPError will be automatically raised.
-
session_exists
(alias)¶ Return True if the session has been already created
alias
that has been used to identify the Session object in the cache
-
status_should_be
(expected_status, response, msg=None)¶ Fails if response status code is different than the expected.
expected_status
could be the code number as an integer or as string. But it could also be a named status code like ‘ok’, ‘created’, ‘accepted’ or ‘bad request’, ‘not found’ etc.The
response
is the output of other requests keywords likeGet Request
.A custom message
msg
can be added to work like built in keywords.
-
to_json
(content, pretty_print=False)¶ Convert a string to a JSON object
content
String content to convert into JSONpretty_print
If defined, will output JSON is pretty print format
-
update_session
(alias, headers=None, cookies=None)¶ Update Session Headers: update a HTTP Session Headers
alias
Robot Framework alias to identify the sessionheaders
Dictionary of headers merge into session
-