Urllib 2には、呼び出される「読み取り」引数があります。私はリクエストを使ってこのスクリプトをPython 3に入れようとしていますが、私はそれを使ってまだ新しいので、私はうまく機能しません。私は一度これを理解すると、それを機能させるために他の何かを考え出す必要があるかもしれないという気持ちがあります。私は現在の温度を華氏で取得しようとしています。私は、トレースバックエラーを取得していますリクエストVS Urllib 2
import requests
import json
f = requests.get('http://api.wunderground.com/api/mykey/geolookup/conditions/q/LA/tickfaw.json')
json_string = f.json()
parsed_json = json.loads(f)
location = parsed_json[str('location')][str('city')]
temp_f = parsed_json['current_observation']['temp_f']
print("Current temperature in %s is: %s" % (location, temp_f))
:
Traceback (most recent call last):
File "C:/Users/jerem/PycharmProjects/webscraper/scratch.py", line 5, in <module>
parsed_json = json.loads(f)
File "C:\Users\jerem\AppData\Local\Programs\Python\Python35-32\lib\json\__init__.py", line 312, in loads
s.__class__.__name__))
TypeError: the JSON object must be str, not 'Response'
Process finished with exit code 1
http://docs.python-requests.org/en/master/user/quickstart/#response-content – Blender
あなたは何を得ていますか?あなたは何を得ることを期待しましたか? – 2rs2ts
質問を更新しました –