为参数添加动态值
add dynamic value to params
我正在使用快速 API 创建小项目以获取 COVID 19 的每日报告。
import http.client ,time
from datetime import datetime
conn = http.client.HTTPSConnection("covid-19-data.p.rapidapi.com")
headers = {
'x-rapidapi-host': "covid-19-data.p.rapidapi.com",
'x-rapidapi-key': "xxxx"
}
# here I want to keep this date value is dynamic "today date"
conn.request("GET", "/report/country/name?date-format=YYYY-MM-DD&format=json&date=2020-06-12&name=uae", headers=headers)
res = conn.getresponse()
data = res.read()
如何使用 datetime.today().strftime('%Y-%m-%d')
使请求与今天的值动态化
您可以在请求的 URL 中将日期作为变量传递。
from datetime import datetime
today_date = datetime.today().strftime('%Y-%m-%d')
conn.request("GET", "/report/country/name?date-format=YYYY-MM-DD&format=json&date="+str(today_date)+"&name=uae", headers=headers)
我正在使用快速 API 创建小项目以获取 COVID 19 的每日报告。
import http.client ,time
from datetime import datetime
conn = http.client.HTTPSConnection("covid-19-data.p.rapidapi.com")
headers = {
'x-rapidapi-host': "covid-19-data.p.rapidapi.com",
'x-rapidapi-key': "xxxx"
}
# here I want to keep this date value is dynamic "today date"
conn.request("GET", "/report/country/name?date-format=YYYY-MM-DD&format=json&date=2020-06-12&name=uae", headers=headers)
res = conn.getresponse()
data = res.read()
如何使用 datetime.today().strftime('%Y-%m-%d')
您可以在请求的 URL 中将日期作为变量传递。
from datetime import datetime
today_date = datetime.today().strftime('%Y-%m-%d')
conn.request("GET", "/report/country/name?date-format=YYYY-MM-DD&format=json&date="+str(today_date)+"&name=uae", headers=headers)