Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 请求。不使用&;性格_Python_Python Requests - Fatal编程技术网

Python 请求。不使用&;性格

Python 请求。不使用&;性格,python,python-requests,Python,Python Requests,我正在使用以下url进行requests.get调用: https://api.datasource.com/apps/ios/ranking?countries=NL&categories=Overall > Kids > 5 & Under&device=ios&ranks=1000 我收到一条带有“categories”的错误消息,其中包含非法值“otheral,这是由于&sign-in-otheral>Kids>5&下的 转义此字符的最佳方法

我正在使用以下url进行requests.get调用:

https://api.datasource.com/apps/ios/ranking?countries=NL&categories=Overall > Kids > 5 & Under&device=ios&ranks=1000
我收到一条带有
“categories”的错误消息,其中包含非法值“otheral
,这是由于&sign-in-otheral>Kids>5&下的


转义此字符的最佳方法是什么?

与直接在URL中传递查询参数不同,
在字典
params
中请求
,并将处理URL编码。(在这种情况下,需要转义与号。)

In[15]:params=dict(countries='NL',categories='Overall>Kids>5岁及以下儿童',device='ios',ranks=1000)
在[16]中:requests.get(“http://www.example.com,params=params)
出[16]:

可能与我想要的完全相同。谢谢!
In [15]: params = dict(countries='NL', categories='Overall > Kids > 5 & Under', device='ios', ranks=1000)

In [16]: requests.get("http://www.example.com", params=params)
Out[16]: <Response [200]>