2017-08-08 22 views

回答

0

您可以使用Prepared Requests以使其起作用,因爲默認情況下,請求將使用requests.util中的requote_uri(uri)函數來幫助處理未引用的未保留字符。如果您已經解析和自己坦然的網址,你可以做以下並覆蓋url領域:

from requests import Session, Request 

s = Session() 

req = Request('GET', 'http://localhost:8008?name=kevin%2Eemckinsey') 

# This will use `requote_uri` to unquote unreserved characters so %2E becomes a `.` 
prepped = req.prepare() 

# Forcing the `url` field to be a URL we specified. 
prepped.url = 'http://localhost:8008?name=kevin%2Emckinsey' 

resp = s.send(prepped) 

print(resp.url) 
print(resp.json()) 

# http://localhost:8008?name=kevin%2Emckinsey 
# PHP's $_SERVER['REQUEST_URI'] returns: 
# {'name': '/?name=kevin%2Emckinsey'} 

這似乎是一個骯髒的把戲給我,但據我所知,有沒有辦法告訴請不要解除引用特定的字符。

+0

謝謝!這確實解決了這個問題。 –