Python请求 - 在查询字符串

时间:2016-10-05 19:57:18

标签: python python-requests

当通过python请求发送数据请求时,我需要在查询字符串的开头专门添加一些东西。我试过通过dicts和json字符串传递数据而没有运气。

请求产生的请求:

/apply/.../explain?%7B%22......

由交互式API文档(Swagger)生成的请求:

/apply/.../explain?record=%7B%22....

我的数据的键值对遵循上面的摘录。

最终,我认为缺少的部分是由他们的文档产生的 record = 。它是唯一与请求产生的不同的部分。

目前,我已经设置了类似的内容:

import requests
s = requests.Session()
s.auth = requests.auth.HTTPBasicAuth(username,password)
s.verify = certificate_path

# with data below being a dictionary of the values I need to pass.
r = s.get(url,data=data)

我正在尝试包含以下文档的图片,但是还没有足够的声誉:

apply/model/explain documentation

2 个答案:

答案 0 :(得分:0)

' GET'请求没有数据,这些数据用于' POST'和朋友。

您可以使用ADODB.Recordset kwarg发送查询字符串参数:

Array

答案 1 :(得分:-1)

从评论中我觉得有必要解释一下。

http://example.com/sth?key=value&anotherkey=anothervalue

假设你有一个像上面这样的网址,以便用python请求调用你只需要编写

 response = requests.get('http://example.com/sth', params={
                          'key':'value', 
                           'anotherkey':'anothervalue'
                         })

请注意,如果您的价值或您的密钥中包含任何特殊字符,则会在您的问题中转义为%7B%2部分网址的原因。

相关问题