간단한 CLI 앱을 사용하여 날씨 데이터를 검색하려고합니다. 불행히도 나는 초기 단계에 갇혀 있기 때문에 이것으로는별로 멀지 않았다. 이것은 지금까지 내 코드입니다 :pywapi로 사용자 입력에서 위치 ID 가져 오기
도시를 요청import pywapi, string
loc=input("What is the city you're closest to?")
loc=loc.lower
#this will give you a dictionary of all cities in the world with this city's name Be specific (city, country)!
loc_id=pywapi.get_location_ids(loc)
#apparently this is a needed workaround to access last item of dictionary
for i in loc_id:
loc_id=i
#before I go on to code anything further, I just want to use print to check that I've got the two variables I need
print (loc,loc_id)
, 나는 예 또는 런던, 영국 런던을 입력 할 수 있지만, 모두 오류 던져 : (이것은 내 로컬 컴퓨터에)
Traceback (most recent call last):
File "get_weather.py", line 7, in <module>
loc_id=pywapi.get_location_ids(loc)
File "/home/james/.local/lib/python3.4/site-packages/pywapi.py", line 825, in get_location_ids
loc_id_data = get_loc_id_from_weather_com(search_string)
File "/home/james/.local/lib/python3.4/site-packages/pywapi.py", line 856, in get_loc_id_from_weather_com
url = LOCID_SEARCH_URL % quote(search_string)
File "/usr/lib/python3.4/urllib/parse.py", line 694, in quote
return quote_from_bytes(string, safe)
File "/usr/lib/python3.4/urllib/parse.py", line 719, in quote_from_bytes
raise TypeError("quote_from_bytes() expected bytes")
TypeError: quote_from_bytes() expected bytes
을 내가 Pythonanywhere
을 사용하고 때
그리고 다른이 오류는 것입니다
Traceback (most recent call last):
File "/home/pydavith/get_weather.py", line 7, in <module>
loc_id=pywapi.get_location_ids(loc)
File "/home/pydavith/.local/lib/python3.6/site-packages/pywapi.py", line 825, in get_location_ids
loc_id_data = get_loc_id_from_weather_com(search_string)
File "/home/pydavith/.local/lib/python3.6/site-packages/pywapi.py", line 852, in get_loc_id_from_weather_co
m
search_string = unidecode(search_string)
File "/usr/local/lib/python3.6/dist-packages/unidecode/__init__.py", line 48, in unidecode_expect_ascii
bytestring = string.encode('ASCII')
AttributeError: 'builtin_function_or_method' object has no attribute 'encode'
사람이 잘못 여기에 무슨 일 어떤 생각을 가지고 있습니까? 나는 duckduckgoed하고 광범위하게 봤 거든,하지만 아무것도 밝혀지지 않았다. 도와 주시면 감사하겠습니다!
두 가지 다른 버전의 Python (3.4 및 3.6)을 사용하고 있으므로 두 가지가 다른 이유를 설명 할 수 있습니다. 오류 자체는 아닙니다. – hwjp