Answer the question
In order to leave comments, you need to log in
TypeError: 'str' object is not callable. How to fix it?
I am writing a program that should take a photo from a site and save it to a computer. Everything works separately, but not together, how to fix this error?
import json
import urllib.request
import random
from datetime import date, timedelta
import os
import shutil
import requests
os.system('cls')
last_date = (date.today())
# yesterday = print(date.today() + timedelta(days=-1))
# fist_date = date(1995, 6, 16)
link_today = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&date=" + str(last_date)
# link_yesterday = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&date=" + str(yesterday)
# link_random = "https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&date=" + str()
open_link = urllib.request.urlopen(link_today)
data = open_link.read()
data.decode('utf-8')
data = eval(data)
with open('data.json', 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
with open('data.json', 'r', encoding='utf-8') as s:
text = json.load(s)
print(text["url"])
d = str(text["url"])
filelName =d().split("/")[-1]+".jpg" #ЗДЕСЬ ОШИБКА!
answer = requests.get(d, stream=True)
if answer.status_code == 200:
answer.raw.decode_content = True
with open(filelName, 'wb') as info:
shutil.copyfileobj(answer.raw, info)
print("Kuvanlataaminen onnistui", filelName)
else:
print("Kuvaa ei voitu ladata.")
Current_Date = filelName.datetime.today.strftime ('%d-%b-%Y')
os.rename(r'C:\Python\15.py' + filelName ,r'C:\Python\15.py' + str(Current_Date) + '.jpg')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question