Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for httpx #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions aws_requests_auth/aws_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
except ImportError:
# python 3
from urllib.parse import quote, urlparse

try:
# python 2
basestring
except NameError:
# python 3
basestring = str

import requests

Expand Down Expand Up @@ -131,7 +138,11 @@ def get_aws_request_headers(self, r, aws_access_key, aws_secret_access_key, aws_

# Create payload hash (hash of the request body content). For GET
# requests, the payload is an empty string ('').
body = r.body if r.body else bytes()
if hasattr(r, "body"):
body = r.body if r.body else bytes()
else:
body = r.stream.body if r.stream and r.stream.body else bytes()

try:
body = body.encode('utf-8')
except (AttributeError, UnicodeDecodeError):
Expand Down Expand Up @@ -192,7 +203,10 @@ def get_canonical_path(cls, r):
Create canonical URI--the part of the URI from domain to query
string (use '/' if no path)
"""
parsedurl = urlparse(r.url)
if isinstance(r.url, basestring):
parsedurl = urlparse(r.url)
else:
parsedurl = r.url

# safe chars adapted from boto's use of urllib.parse.quote
# https://github.com/boto/boto/blob/d9e5cfe900e1a58717e393c76a6e3580305f217a/boto/auth.py#L393
Expand Down Expand Up @@ -220,7 +234,10 @@ def get_canonical_querystring(cls, r):
"""
canonical_querystring = ''

parsedurl = urlparse(r.url)
if isinstance(r.url, basestring):
parsedurl = urlparse(r.url)
else:
parsedurl = r.url
querystring_sorted = '&'.join(sorted(parsedurl.query.split('&')))

for query_param in querystring_sorted.split('&'):
Expand Down