Уведомления

Группа в Telegram: @pythonsu

#1 Фев. 5, 2022 02:26:47

grifon4ik
Зарегистрирован: 2022-02-05
Сообщения: 1
Репутация: +  0  -
Профиль   Отправить e-mail  

Getting response from URL after changing config.json properties with Python

Мои приветствия.
——————–
Задание:
Read config.json file located in :
/data/python/config.json
make a GET request to the URL under ‘url’ key and add the first 15 characters
to a key name ‘content’ in the json file.
config.json:
{“url”: "https://www.google.com“}
config.json after code run:
{”url“: ”https://www.google.com“, ”content“: ”<first15>“}
Where <first15> should be the first 15 characters from the response.

——————–
Написан код:

import json

import requests

with open(”/home/Exam/Python/data/python/config.json“, ”r“) as f:
#with open(”home/Exam/Python/config.json“, ”r") as f:
config = json.load(f)

result = requests.get(config)

config = result.text

with open(“/home/Exam/Python/data/python/config.json”, “w”) as f:
json.dump(config, f)


——————–
Но не совсем понятно что должно измениться после изменения conf.json файла….
И Where <first15> should be the first 15 characters from the response.
Буду рад пояснению

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version