roberthsu2003 / __2024_07_29_1_3_night__

2024_07_29_1_3_巨匠AI
22 stars 2 forks source link

請下載日射量json資料,存檔名稱為'台灣日射量.json' #7

Open roberthsu2003 opened 2 months ago

roberthsu2003 commented 2 months ago
url = 'https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON'
WayneChou-bot commented 2 months ago
# 請下載日射量json資料,存檔名稱為'台灣日射量.json'
import requests
from requests.exceptions import HTTPError,ConnectionError,Timeout

try:
    url = "https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON"
    response = requests.get(url)
    response.raise_for_status()
    content = response.text
    #print(content)
except ConnectionError:
    print("連線伺服器發生錯誤")
except Timeout:
    print("伺服器忙碌,沒有回應")
except HTTPError:
    print("伺服器回應連線錯誤")
except Exception:
    print("不知名的錯誤")
else:
    file = open("台灣日射量.json",encoding="utf-8",mode="w",newline="")
    file.write(content)
    file.close()
hellno3009 commented 2 months ago
import requests
from requests.exceptions import HTTPError,ConnectionError,Timeout
try:
    url = 'https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON'
    response = requests.get(url)
    response.raise_for_status()
    content = response.text
    print(content)
except ConnectionError:
    print("連線伺服器發生錯誤")
except Timeout:
    print("伺服器太忙,沒有回應")
except HTTPError:
    print("伺服器回應連線錯誤")
except Exception:
    print("不知名的錯誤")
else:
    file = open('abc.json',encoding='utf-8',mode='w',newline='')
    file.write(content)
    file.close()
Srdell7 commented 2 months ago
import requests 
from requests.exceptions import HTTPError,ConnectionError,Timeout

try:
    url = 'https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON'
    response = requests.get(url)
    content = response.text
except HTTPError:
    print("伺服器連線錯誤")
except ConnectionError:
    print("連線時發生錯誤")
except Timeout:
    print("伺服器忙碌中,請稍後再試")
except Exception:
    print("未知的錯誤")
else:
    file = open('台灣日射量.json',encoding='utf-8',mode='w',newline='')
    file.write(content)
    file.close()
FriendlyLu commented 2 months ago
import requests
from requests.exceptions import HTTPError,ConnectionError,Timeout
#下載
try:
    url = 'https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON'
    response = requests.get(url)
    response.raise_for_status()
    #print(type(response))
    content = response.text
    print("json 資料下載成功")

    #存文字檔
    try:
        file = open('台灣日射量.json',encoding='utf-8',mode='w',newline='')
        file.write(content)
        file.close()

        print("台灣日射量.json 資料存檔成功")
    except Exception:
        print("台灣日射量.json 資料存檔失敗")

except ConnectionError:
    print("連線伺服器發生錯誤")
except Timeout:
    print("伺服器太忙,沒有回應")
except  HTTPError:
    print("伺服器回應連線錯誤")
except Exception:
    print("不知名的錯誤")
yawenny commented 2 months ago
import requests
from requests.exceptions import HTTPError,ConnectionError,Timeout
try:
    url = 'https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON'
    response = requests.get(url)
    response.raise_for_status()
    #print(type(response))
    content = response.text
    #print(content)
except ConnectionError:
    print("連線伺服器異常")
except Timeout:
    print("伺服器太忙,沒有回應")
except HTTPError:
    print("伺服器回應連線錯誤")
except Exception:
    print("不知名的錯誤")
else:
    file = open('台灣日射量.json',mode='w',encoding='utf-8',newline='')
    file.write(content)
    file.close()
Oscar-Lee-20211298 commented 2 months ago
import requests
from requests.exceptions import HTTPError,ConnectionError,Timeout
#下載
try:
   url = 'https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON'
   response = requests.get(url)
   response.raise_for_status()
   content = response.text
   print(content)
except ConnectionError:
    print("連線伺服器發生錯誤")
except Timeout:
    print("伺服器太忙,沒有回應")
except  HTTPError:
    print("伺服器回應連線錯誤")
except Exception:
    print("不知名的錯誤")
else:
    file = open('台灣日射量.json',encoding='utf-8',mode='w',newline='')
    file.write(content)
    file.close()
grace588 commented 2 months ago
import requests
from requests.exceptions import HTTPError,ConnectionError,Timeout
try:
    url = 'https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON'
    response = requests.get(url)
    response.raise_for_status()
    content = response.text
    print(content)
except ConnectionError:
    print("連線伺服器發生錯誤")
except Timeout:
    print("伺服器太忙,沒有回應")
except HTTPError:
    print("伺服器回應連線錯誤")
except Exception:
    print("不知名的錯誤")
else:
    file = open('123.json',encoding='utf-8',mode='w',newline='')
    file.write(content)
    file.close()
handsomeyoxi commented 2 months ago
import requests
from requests.exceptions import HTTPError,ConnectionError,Timeout
try:
    url = 'https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON'
    response = requests.get(url)
    response.raise_for_status()
    print(type(response))
    content = response.text
    print(content)
except ConnectionError:
    print("連線伺服器發生錯誤")
except Timeout:
    print("伺服器太忙,沒有回應")
except  HTTPError:
    print("伺服器回應連線錯誤")
except Exception:
    print("不知名的錯誤")
else:
    file = open("abc.JSON", encoding = "utf-8", mode = "w", newline = ""  )
    file.write(content)
    file.close()
kxyzqo commented 2 months ago
import requests
from requests.exceptions import HTTPError,ConnectionError,Timeout

try:
    url = 'https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON'
    response = requests.get(url)
    response.raise_for_status()
    #print(type(response))
    content = response.text
    #print(content)
except ConnectionError:
    print("連線伺服器發生錯誤")
except Timeout:
    print("伺服器忙碌中 沒有回應")
except  HTTPError:
    print("伺服器回應連線錯誤")
except Exception:
    print("未知的錯誤")
else:
    file = open('台灣日射量.json',encoding='utf-8',mode='w',newline='')
    file.write(content)
    file.close()
teddy-wz commented 2 months ago
import requests
from requests.exceptions import HTTPError,ConnectionError,Timeout
#下載
try:
    url = 'https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON'
    response=requests.get(url)
    response.raise_for_status()
    #print(type(response))
    content=response.text
    #print(content)
except ConnectionError:
    print("連線伺服器異常")
except Timeout:
    print("伺服器太忙,沒有回應")
except HTTPError:
    print("伺服器回應連線錯誤")
except Exception:
    print("不知名的錯誤")
else:
    file = open('台灣日射量.json',encoding='utf-8',mode='w',newline='')
    file.write(content)
    file.close()
SophiaSu0925 commented 2 months ago
import requests
from requests.exceptions import HTTPError, ConnectionError, Timeout
try:
  url = 'https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON'
  response = requests.get(url)
  response.raise_for_status()
  content = response.text
  print(content)
except ConnectionError:
  print("連線伺服器發生錯誤")
except Timeout:
  print("伺服器太忙,沒有回應")
except  HTTPError:
  print("伺服器回應連線錯誤")
except Exception:
  print("不知名的錯誤")
else:
  file = open('台灣日射量.json',encoding='utf-8',mode='w',newline='')
  file.write(content)
  file.close()
  print("檔案下載完成")
patrick11330619 commented 2 months ago
import requests
from requests.exceptions import HTTPError,ConnectionError,Timeout
#下載
try:
    url = 'https://opendata.cwa.gov.tw/fileapi/v1/opendataapi/O-A0091-001?Authorization=rdec-key-123-45678-011121314&format=JSON'
    response = requests.get(url)
    response.raise_for_status()
    content = response.text

except ConnectionError:
    print("連線伺服器發生錯誤")
except Timeout:
    print("伺服器太忙,沒有回應")
except  HTTPError:
    print("伺服器回應連線錯誤")
except Exception:
    print("不知名的錯誤")
else:
    file = open('v台灣日射量.json',encoding='utf-8',mode='w',newline='')
    file.write(content)
    file.close()