twilio package

Subpackages

Submodules

twilio.request_validator module

class twilio.request_validator.RequestValidator(token)[source]

Bases: object

compute_hash(body)[source]
compute_signature(uri, params)[source]

Compute the signature for a given request

Parameters:
  • uri – full URI that Twilio requested on your server
  • params – post vars that Twilio sent with the request
Returns:

The computed signature

get_values(param_dict, param_name)[source]
validate(uri, params, signature)[source]

Validate a request from Twilio

Parameters:
  • uri – full URI that Twilio requested on your server
  • params – dictionary of POST variables or string of POST body for JSON requests
  • signature – expected signature in HTTP X-Twilio-Signature header
Returns:

True if the request passes validation, False if not

twilio.request_validator.add_port(uri)[source]

Add the port number to a URI

Parameters:uri – parsed URI that Twilio requested on your server
Returns:full URI with a port number
Return type:str
twilio.request_validator.compare(string1, string2)[source]

Compare two strings while protecting against timing attacks

Parameters:
  • string1 (str) – the first string
  • string2 (str) – the second string
Returns:

True if the strings are equal, False if not

Return type:

bool

twilio.request_validator.remove_port(uri)[source]

Remove the port number from a URI

Parameters:uri – parsed URI that Twilio requested on your server
Returns:full URI without a port number
Return type:str

Module contents