How to sign a request with Python?

Viewed 56

I am working on a 3rd party API, and unfortunately, the support is quite bad without much detailed document, they just provided an example on Ruby to sign a request before making the call to API, like this

# Config your keys
access_id = "YOUR_ACCESS_KEY"
secret_key = "YOUR_SECRET_KEY"

api_endpoint = "https://api.example.com/endpoint"

# Make a request
request = Curl::Easy.new(api_endpoint)
## always set header Content-Type with application/json
request.headers["Content-Type"] = "application/json"

# Sign the request with the keys
# https://www.rubydoc.info/gems/api-auth/2.4.1/ApiAuth.sign!
signed = ApiAuth.sign!(request, access_id, secret_key, :override_http_method => "GET")

# signed
signed.perform
signed.body_str

I've tried to experiment with requests but not successful. Is there any library from Python or how can I implement this chunk of Ruby code to Python?

Thank you very much

0 Answers
Related