【发布时间】:2014-06-23 04:30:33
【问题描述】:
我正在尝试在 python 中使用 requests.get() 获取以下格式的 URL:
http://api.example.com/export/?format=json&key=site:dummy+type:example+group:wheel
#!/usr/local/bin/python
import requests
print(requests.__versiom__)
url = 'http://api.example.com/export/'
payload = {'format': 'json', 'key': 'site:dummy+type:example+group:wheel'}
r = requests.get(url, params=payload)
print(r.url)
但是,URL 被百分比编码,我没有得到预期的响应。
2.2.1
http://api.example.com/export/?key=site%3Adummy%2Btype%3Aexample%2Bgroup%3Awheel&format=json
如果我直接传递 URL,这将有效:
url = http://api.example.com/export/?format=json&key=site:dummy+type:example+group:wheel
r = requests.get(url)
有没有办法以原始形式传递参数 - 没有百分比编码?
谢谢!
【问题讨论】:
-
这是一个standard。它有什么问题?
-
@alecxe:我正在查询的网站似乎无法使用百分比编码的 URL,并且我得到了意外的响应。
-
我在
location=43.585278,39.720278中使用 Google Maps API 和逗号遇到了这个问题,但我没有找到解决方案。
标签: python url python-requests percent-encoding