Python furl library - Is there a way to add a parameter to a url without url encoding it? -
i have url need add api key parameter. key has % , other characters in , should not url encoded, there way furl?
heres current code:
request_url = furl('http://www.domain.com/service/') \ .add({ 'format' : 'json', 'location' : address_line_1 + ',' + city + ',' + state, 'key' : app_key }).url
i have url need add api key parameter. key has % , other characters in , should not url encoded
that can't true. must url-encoded. otherwise, end either invalid url, or url doesn't mean wanted.
for example, let's key 123%456%789. if send http://www.domain.com/service/?format=json&key=123%25456%25789, web service on other end 123%456%789, succeed. if send http://www.domain.com/service/?format=json&key=123%456%789, web service on other end 123e6x9, fail.
so, example correct, , shouldn't need anything.
if, reason, you're url-encoding app_key before here… well, don't. name that, i'm guessing it's constant literal copied , pasted module, means had manually url-encode , copy , paste result. don't that, , you're fine.
if got app_key in url-encoded form, can decode with, e.g., urlparse.parse_qs, or furl.
but if none of seems reasonable…
is there way furl?
no. see encoding section of docs. furl works on decoded query string names , values.
but there's easy way around this. url isn't complicated of thing, , furl designed allow mix , match manually- , programmatically- created bits. of examples in readme show that, such furl('http://www.google.com/?one=1').add({'two':2}).url. so, if you've got pre-encoded "key=123%25456%25789" somewhere, stick on string manually before giving furl:
request_url = furl('http://www.domain.com/service/?key={}'.format(app_key)) \ .add({ 'format' : 'json', 'location' : address_line_1 + ',' + city + ',' + state, }).url hacky? well, yes, in you're side-stepping furl's encoding, that's you're asking how do.
Comments
Post a Comment