kennethreitz/requests — Issue #406: Ability to override quote per request / session
Author: vladimir-webdev
Created: 2012-02-02 11:44:23+00:00
State: open

Amazon S3 allows serving images with signed URLs. Such URL looks like:

https://BUCKET.s3.amazonaws.com/IMAGE?AWSAccessKeyId=KEY&Expires=EXPIRES&Signature=SIGNATURE

So site should calculate SIGNATURE for given URL and expiration time. Then I can fetch that URL using python-requests.

But the problem is that some languages (in my case PHP) does not properly quote URL (in my case PHP does not quote ":"). So while PHP site signs URL like "/some:image:name" python-requests tries to get URL like "/some%3Aimage%3Aname" and S3 refuses to allow access:

SignatureDoesNotMatch

That happens because PHP and Python encode URLs in different ways. And it would be nice if we have opportunity to override quote() per session. It may look like:

class PhpCompatSession(Session):
def quote(self, url):
....

s = PhpCompatSession()
requests.get('URL', session=s)

I can submit a patch if this proposal sounds good for you.