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

1.0.2 support. Python 3 endode / decode problems fixed #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hebelken
Copy link

This lets people use Python3, and newer versions of httpie. maybe.

@costi
Copy link

costi commented Apr 16, 2021

Tested - this works for me. Let's get it merged.

@costi
Copy link

costi commented Apr 16, 2021

Actually just found an issue:
When doing a POST without a Content-Type:

http: error: AttributeError: 'str' object has no attribute 'decode'

The issue is with content_type.decode() because it's a string.

The fix:

content_type = r.headers.get('content-type')
if not content_type:
    content_type = b''

If we remove the decode() from content_type instead, it works for empty Content-Type header, but it doesn't sign properly when submitting a Content-Type.

path = url.path
if url.query:
path = path + '?' + url.query

string_to_sign = '%s,%s,%s,%s,%s' % (method, content_type, content_md5, path, httpdate)
digest = hmac.new(self.secret_key, string_to_sign, hashlib.sha1).digest()
string_to_sign = '%s,%s,%s,%s,%s' % (method, content_type.decode(), content_md5, path, httpdate)
Copy link

@costi costi Apr 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to take care the empty content-type case.

if not content_type:
            content_type = ''

Error:
http: error: AttributeError: 'str' object has no attribute 'decode'

Change line 23 to content_type = b''

@costi
Copy link

costi commented Apr 16, 2021

After fixing it let's release it
@packrat386 do you have access to https://pypi.org/project/httpie-api-auth/ ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants