values with space doesn't pass with %20

KenKen

New Member
somehow other special characters can be passed in the values, but space doesn't. I tried %20 and + for whitespace but no luck. Is there anything that I am missing on this?

For eg)
'Senior programmer' cannot be passed even though I change it to 'Senior%20programmer' or 'Senior+programmer' by using urllib.quote(myjob) in Python.

Posting this problem here with my luck!

Thank you.
 
@KenKen - Please provide some code to show how your going about this as it gives us a better idea on how to assist otherwise we are guessing just as much as you are.

Otherwise urllib should pass the url with the whitespaces if you import urllib

Code:
import urllib
url = urllib.quote("http://www.mailwizz.com/my url with whitespaces")

Thanks
 
Hi BirdyUK, found that it works when I pass data as param (urllib.urlencode(params)) instead of encoding each value with urllib.quote(value)

Thank you for your fast response. Hope this post can be helpful for other users.

Code:
def subscribe_user_mail():
#Required POST values
method = 'POST'
action = 'lists'
uid = '1234uid'
params = {
    'EMAIL':'jojo@aol.com',
   'FNAME':'Jo jo'
}
url = "http://mydomain.com/api/index.php/%s" % (action+'/'+uid+'/subscribers?'+urlllib.urlencode(params))
public_key = '1234publickey'
private_key = '1234privatekey'
current_time = str(int(time.time()))
remote_addr = '190.190.105.200'

#Add three values into the header
headers_o = {
'X-MW-PUBLIC-KEY': public_key,
'X-MW-TIMESTAMP': current_time,
'X-MW-REMOTE-ADDR': remote_addr
}

#Order header keys by asc
headers = collections.OrderedDict(sorted(headers_o.items()))

#Create special signature
signature_string = ''.join([method.upper(), ' ', url, '&', urllib.urlencode(headers)])
signature = hmac.new(str(private_key), signature_string, hashlib.sha1).hexdigest()

#Add special signature in the header
headers['X-MW-SIGNATURE'] = signature

#Send POST request
response = requests.post(
url=url,
headers=headers,
data={'EMAIL':'johnkikiki%40gmail.com',FNAME:'kanye%20west'}
)
#Print output
return response
#Print POST url and url accessed via API
return response.url +','+signature_string
 
Last edited:
Back
Top