안녕하세요. 기상 조건에 대한 간단한 인쇄를 수행하기 위해 python 3으로 API 요청을 보내려고합니다. 누군가가 저에게 잘못된 정보를 줄 수 있습니까? 나는 여기에서 배울 것이 많다, 그래서 학습 곡선은 가파르다! 미안 슈퍼 질문을하는 경우, 두 사이에 사용할 수있는 더 나은 코드는 무엇입니까? 적어도 내가 일하고 얻을 수있는 것들을 가지고 ... 고맙습니다. 아래의 두 코드는 WU 웹 사이트 & Github에서받은 예제 스크립트입니다.API 요청 Weather Underground
from urllib.request import urlopen
import json
api_key = ""
date = "20170901"
zip_code = "53711"
response = urlopen("http://api.wunderground.com/api/%s/history_%s/q/%s.json"
% (api_key, date, zip_code))
json_data = response.read().decode('utf-8', 'replace')
data = json.loads(json_data)
for observation in data (['history']['observations']):
print("Date/Time: " + observation['date']['pretty'])
print("Temperature: " + observation['tempi'])
print("Humidity: " + observation['hum'])
이것이 두 번째 ": 이 형식 오류 목록 지수는 정수 또는 슬라이스 있어야 STR,하지 데이터 관측 ([ '이력'] [ '관찰'])"첫 번째 코드 나에게 오류를 범 내 첫 번째 API 요청에 시도, 그러나 그것은 나에게 오류 줄 "형식 오류 : %를 지원되지 않는 피연산자 유형 (들) : 'NoneType'와 '튜플'"프로가에 newb을 줄 수있는
from urllib.request import urlopen
import json
f = urlopen('http://api.wunderground.com/api//geolookup/conditions/q/IA/Cedar_Rapids.json')
json_string = f.read()
parsed_json = json.loads(json_string)
location = parsed_json['location']['city']
temp_f = parsed_json['current_observation']['temp_f']
print ("Current temperature in %s is: %s") % (location, temp_f)
f.close()
모든 팁 이와 같은 자체 교육 주제는 크게 감사드립니다 ... WU에서 내 API 키가 작동하는 것을 볼 수 있습니다 ... 그러나 코드가 잘못되었습니다. (
안녕하세요, wunderweather 및 tar.gz 추출 및 설치 프로세스 용 PIP 설치를 실행했지만 여전히 모듈을 찾을 수 없습니다. 오류가 발생했습니다 ... 어떤 팁이 있습니까? pip 설치'py -3.6 -m pip install WunderWeather'는 정상적으로 작동하지만 여전히 오류가 발생합니다 ... – HenryHub