python - 在请求中添加路径参数
问题描述
如果我有:
https://exampleurl/{path}
这样的 URL,那么requests
我应该使用模块中的哪些功能来填写路径?我知道我可以传递类似的东西:
query = {'q0':'path_params','q1':'hello', 'q2':'world'}
并将其传递给requests.get(url, params=query)
. 但这会产生这样的结果:
https://exampleurl/?q1=hello&q2=world
代替https://exampleurl/path_params?q1=hello&q2=world
解决方案
您可以在 url 上做字符串格式来填写路径参数。
url = 'https://exampleurl/{path_param}'
api_call = url.format(path)
推荐阅读
- javascript - 我应该访问 React 组件中的文档以创建事件侦听器吗?
- r - If I want to upper version for a CRAN exist R package (from 0.2.0 to 0.2.1) , do I need to delete "CRAN-RELEASE" in R package?
- c++ - 无法计算模型具有的顶点数。(不确定数组的大小)
- c++ - 如何避免定义相似类的代码重复
- amazon-web-services - 如何从 PHP SDK 将 AWS CloudFront 分发链接到 AWS Elemental MediaPackage
- javascript - React Native 将个人资料图片上传到 Firebase
- python - 设置系统环境变量
- android - 无法访问“com.theapp.name.Application”的超类型“android.app.Application” - FCM
- java - 以编程方式使用 onclick 方法添加许多 CardView
- owl - 如何使用不同的 ModelSpec 将 JENA OntModel 克隆到另一个