-1

高度なコーディング コースで API を使用しようとしていますが、何をしても、常にこのエラーが発生します。どうすれば...ええと...エラーが発生しませんか? 前もって感謝します。

ETA: IDLE 3.4 を使用していると思います。

from pprint import pprint
import requests
import encodings.idna
r = requests.get('http://api.openweathermap.org/data/2.5/weather?q=London')
pprint(r.json())

今、次のようなエラーが表示されます。

Traceback (most recent call last):
  File "/Users/lilyevans/APIproject.py", line 4, in <module>
    r = requests.get('http://api.openweathermap.org/data/2.5/weather?q=London')
AttributeError: 'module' object has no attribute 'get'
4

1 に答える 1

0

シェルでは、一度に複数のステートメントを実行することはできません。

>>> x = 5
y = 6
SyntaxError: multiple statements found while compiling a single statement
You need to execute them one by one:

>>> x = 5
>>> y = 6
>>>

複数のステートメントが宣言されている場合は、後で実行されるスクリプトが表示されていることを意味します。しかし、対話型インタープリターでは、一度に複数のステートメントを実行することはできません。

このコードを実行してみてください。行がシフト入力ではなく入力で区切られていることを確認してください

from pprint import pprint
import requests
import encodings.idna
r = requests.get('http://api.openweathermap.org/data/2.5/weather?q=London')
pprint(r.json())


Out[]:

{u'base': u'cmc stations',
 u'clouds': {u'all': 0},
 u'cod': 200,
 u'coord': {u'lat': 51.51, u'lon': -0.13},
 u'dt': 1415047029,
 u'id': 2643743,
 u'main': {u'humidity': 87,
           u'pressure': 989,
           u'temp': 279.78,
           u'temp_max': 281.15,
           u'temp_min': 278.15},
 u'name': u'London',
 u'sys': {u'country': u'GB',
          u'id': 5091,
          u'message': 0.0299,
          u'sunrise': 1414997905,
          u'sunset': 1415032183,
          u'type': 1},
 u'weather': [{u'description': u'Sky is Clear',
               u'icon': u'01n',
               u'id': 800,
               u'main': u'Clear'}],
 u'wind': {u'deg': 230, u'speed': 2.1, u'var_beg': 190, u'var_end': 260}}
于 2014-11-03T21:17:20.763 に答える