Есть код:
import requests
import json
#1 Приём сообщений
#2 Отсылка сообщений
URL = 'https://api.telegram.org/botтокен скрыт/'
def write_json(data, filename='answer.json'):
with open(filename, 'w') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
def get_updates():
url = URL + 'getUpdates'
r = requests.get(url)
write_json(r.json)
def main():
get_updates()
if __name__ == '__main__':
main()
При запуске на windows получаю ошибку:
Traceback (most recent call last):
File "C:\Users\Дом\Desktop\Py\PY\flaskapp\flaskbot.py", line 41, in <module>
main()
File "C:\Users\Дом\Desktop\Py\PY\flaskapp\flaskbot.py", line 34, in main
get_updates()
File "C:\Users\Дом\Desktop\Py\PY\flaskapp\flaskbot.py", line 31, in get_updates
write_json(r.json)
File "C:\Users\Дом\Desktop\Py\PY\flaskapp\flaskbot.py", line 26, in write_json
json.dump(data, f, indent=2, ensure_ascii=False)
File "C:\Users\Дом\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 179, in dump
for chunk in iterable:
File "C:\Users\Дом\AppData\Local\Programs\Python\Python38\lib\json\encoder.py", line 438, in _iterencode
o = _default(o)
File "C:\Users\Дом\AppData\Local\Programs\Python\Python38\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type method is not JSON serializable
Что делать?