我如何请求 URL 已经在 python 请求中进行了 URL 编码?

How can I request a URL that is already URL-encoded in python-requests?

我正在尝试请求以下 URL:

https://www.sainsburys.co.uk/shop/gb/groceries/shiraz/barossa-valley-estate-grenache-shiraz-mourv%C3%A8dre-75cl

用 urllib 解码并打印它显示它是:

In [36]: print urllib.unquote(url)
https://www.sainsburys.co.uk/shop/gb/groceries/shiraz/barossa-valley-estate-grenache-shiraz-mourvèdre-75cl

即重音 "e"。

但似乎无论我用 import requests; requests.get(...) 请求什么,我都会收到 404。

get 方法的正确输入是什么?

你应该在将 url 传递给 urllib unquote

后用 'latin-1' 解码
>>> 
>>> k = "https://www.sainsburys.co.uk/shop/gb/groceries/shiraz/barossa-valley-estate-grenache-shiraz-mourv%C3%A8dre-75cl"
>>> r = requests.get(urllib.unquote(k).decode("latin-1"))
>>> r.status_code
200
>>>