我有一個字典如下Python的編碼空格被正確編碼
params = {
'response_type': 'token',
'client_id': o_auth_client_id,
'redirect_url': call_back_url,
'scope': 'activity heartrate location'
}
print urllib.urlencode(params)
和UM編碼它
但是在結果中
REDIRECT_URL = HTTP%3A%2F%2F127.0.0 .1%3A8084%2Fagile_healtg%2Faccess_token%2F & response_type = token & client_id = xxxxxx & scope = activity + heartrate + location
嗯越來越像上述 不幸的是空間被編碼爲+號
,但結果應該是
範圍=活性%20nutrition%20heartrate
我可如何實現Python中的空格的正確編碼?
這是在查詢空間正確的編碼。試試'「http://www.google.com/?」 + urllib.urlencode({「q」:「http query string」})'。 – zvone
@zvone我需要空格作爲%20編碼空格,因爲+不正確 – Kalanamith
但它並不正確。 '+'是查詢字符串參數中空格的正確編碼。 '%20'是路徑元素中空間的編碼。 –