Open roberthsu2003 opened 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()
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()
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()
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("不知名的錯誤")
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()
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()
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()
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()
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()
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()
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("檔案下載完成")
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()