python - How to pass Dynamic values to Url by Loop using Python
问题描述
Below is the code i am using to get values from the repositories. Here i have given like to give data from only page 1. But how to get data from all the pages existing in that repository using loop. And again these data will be posted back to another URL using Post method.
import requests
import json
headers = {
'Content-Type': 'application/json, Accept: application/json',
}
params = (
('dql', 'select u.user_name as USER_NAME,u.user_login_name as USER_LOGIN,u.default_folder as
DEFAULT_FOLDER_PATH, u.last_login_utc_time as USER_LAST_LOGIN, u.user_os_domain as
USER_OS_DOMAIN,u.user_login_domain as USER_LOGIN_DOMAIN,u.user_state as USER_STATE,f.object_name as
DEFAULT_FOLDER_NAME,f.r_creation_date as DEFAULT_FOLDER_CREATION_DATE,f.r_modify_date as
DEFAULT_FOLDER_MODIFY_DATE from dm_user u, dm_folder f where u.default_folder = f.r_folder_path
enable(ROW_BASED)'),
('items-per-page', '2'),
('page', '1'),
)
def requestcall():
myResponse = requests.get('https://1.1.1.1/rest/repositories/hhdht@@', headers=headers,
params=params, verify=False, auth=('@@@@@@', '#######'))
print(myResponse.status_code)
# For successful API call, response code will be 200 (OK)
if myResponse.ok:
# extracting data in json format
data = myResponse.json()
return data
requestcall()
解决方案
Well, you can put page
variable inside the for loop until it reach the max_page
number like this?
def requestcall():
for p in range(max_page):
params=(
('dsql','...')
('page',str(p))
('item-per-page','2')
)
request.get(...params=params)
推荐阅读
- apache-spark - spark 3.0 中的 glob
- java - 如何关闭枚举的反序列化
- reactjs - 在功能组件中反应承诺
- sql-server - Microsoft SQL Server 2016 - 将 varchar 转换为带有 $ 符号和 2 位小数的货币
- sql - 按日期建立日期参数:小时而不是日期
- class - 如何从飞镖颤振中的单个泛型类返回多种类类型?
- postgresql - 将 postgresql 从版本 11 升级到 12 会导致“您的安装引用了丢失的可加载库”
- python - 根据熊猫数据框中的特定ID更改列的值
- wordpress - Htaccess 将 Modula Gallery 图像文件名重写为 LiteSpeed 缓存图像
- javascript - SignalR 锁定按钮