我正在使用Kenneth Retiz的優秀請求包進行Web請求。 Requests Github repository在python3請求中傳遞參數時無需轉義
有時候,我需要在用逗號分隔的參數傳遞,但逗號不是URL編碼,也就是我的網址是這樣的
http://example.site.com/customers?fields=id,first_name,last_name
我無法弄清楚如何格式化查詢參數就是這樣出來的。逗號總是會被轉移到%2C。
我嘗試下面的代碼,但是,這並不工作:
params['fields'] = 'id,first_name,last_name'
url = 'http://example.site.com/customers'
ex = requests.get(url, params = params)
感謝。
供參考,逗號是「[保留字符]( http://tools.ietf.org/html/rfc3986#section-2.2)「,並且*應該被編碼。服務器在使用前解碼參數。你能擴展你爲什麼要讓逗號通過非轉義嗎? –
請考慮以下網址:http://httpbin.org/get?fields = a%2cb%2cc。如果你點擊它,你會看到httpbin服務器接收到一個編碼的URL,但是正確解碼了「fields」參數。 –