day = 1
month = 1
text = 'russia'
api_url = 'https://api.api-ninjas.com/v1/historicalevents?text={},day={},month={}'.format(text, month, day)
response = requests.get(api_url, headers={'X-Api-Key': 'zd4vQLQ3nVfeG1W'})
if response.status_code == requests.codes.ok:
print(response.text)
else:
print("Error:", response.status_code, response.text)
from urllib.parse import urlencode
params = {
"text": 'russia',
"day": 1,
"month": 1
}
param_str = urlencode(params)
# формируем полную ссылку
api_url = f'https://api.api-ninjas.com/v1/historicalevents?{param_str}'
print(api_url) # https://api.api-ninjas.com/v1/historicalevents?text=russia&day=1&month=1
import requests
day = 1
month = 1
text = 'russia'
api_key = 'api key'
api_url = f'https://api.api-ninjas.com/v1/historicalevents?text={text}&day={day}&month={month}'
response = requests.get(api_url, headers={'X-Api-Key': api_key})
if response.status_code == requests.codes.ok:
print(response.text)
else:
print("Error:", response.status_code, response.text)
import requests
# параметры запроса
day = 1
month = 1
text = 'russia'
# формирование url
api_url = 'https://api.api-ninjas.com/v1/historicalevents?text={},day={},month={}'.format(text, day, month)
# headers с ключом API
headers = {
'X-Api-Key': 'zd4vQLQ3nVfeG1W'
}
# отправка запроса
response = requests.get(api_url, headers=headers)
# проверка ответа
if response.status_code == 200:
print(response.json())
else:
print("Error:", response.status_code, response.text)
import requests
api_url = 'https://api.api-ninjas.com/v1/historicalevents'
headers = {
'X-Api-Key': 'zd4vQLQ3nVfeG1W'
}
params = {
'text': 'russia',
'day': 1,
'month': 1
}
response = requests.get(api_url, headers=headers, params=params)
if response.status_code == 200:
print(response.json())
else:
print("Error:", response.status_code, response.text)