気象データを取得するための簡単な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と広範囲にグーグルを持っているが、何も光に来ていない。助けていただければ幸いです!
あなたは2つの異なるバージョンのPython(3.4と3.6)を使用しています。 – hwjp