質問編集履歴

3

質問内容

2019/04/10 17:10

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -2,19 +2,25 @@
2
2
 
3
3
  ``` import json
4
4
 
5
- from urllib.request import urlopen
5
+ from urllib.request import urlopen
6
6
 
7
- import requests
7
+ import requests
8
8
 
9
- def get_hottel_information(HottelNo):
9
+ def get_hottel_information(HottelNo):
10
10
 
11
+
12
+
11
- response=urlopen("https://app.rakuten.co.jp/services/api/Travel/HotelDetailSearch/20170426?format=json&hotelNo="+HottelNo+"&applicationId=1033169620458208128").read()\
13
+ response=urlopen("https://app.rakuten.co.jp/services/api/Travel/HotelDetailSearch/20170426?format=json&hotelNo="+HottelNo+"&applicationId=1033169620458208128").read()\
12
14
 
13
15
  .decode('utf-8')
14
16
 
15
- responseJson=json.loads(response)
17
+
16
18
 
19
+ responseJson=json.loads(response)
20
+
21
+
22
+
17
- return responseJson.get(dict["hottelName"])
23
+ return responseJson.get(dict["hottelName"])
18
24
 
19
25
 
20
26
 

2

2019/04/10 17:09

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- 樂天 API httperror
1
+ 樂天 API type object is not scriptable
test CHANGED
File without changes

1

しつもn

2019/04/10 13:54

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,22 +1,20 @@
1
- 樂天から情報を取り出したい。 そためにHTTPERRORを回避したいです。 APIは樂天トラベルのを使いました。
1
+ 樂天から情報を取り出したい。typeobject is not subscriptable はどうやってとれま。 APIは樂天トラベルのを使いました。
2
2
 
3
- ```python
3
+ ``` import json
4
4
 
5
- import json
5
+ from urllib.request import urlopen
6
6
 
7
- from urllib.request import urlopen
7
+ import requests
8
8
 
9
+ def get_hottel_information(HottelNo):
9
10
 
11
+ response=urlopen("https://app.rakuten.co.jp/services/api/Travel/HotelDetailSearch/20170426?format=json&hotelNo="+HottelNo+"&applicationId=1033169620458208128").read()\
10
12
 
11
- def get_hottel_information(HottelNo):
13
+ .decode('utf-8')
12
14
 
13
- response=urlopen("https://app.rakuten.co.jp/services/api/Travel/HotelDetailSearch/20170426?format=json&hotelNo="+HottelNo+"&applicationId=103d6978eae7da5f6ca0c766e74d0c99").read()\
15
+ responseJson=json.loads(response)
14
16
 
15
- .decode('utf-8')
16
-
17
- responseJson=json.loads(response)
18
-
19
- return responseJson("hottelName")
17
+ return responseJson.get(dict["hottelName"])
20
18
 
21
19
 
22
20
 
@@ -26,32 +24,6 @@
26
24
 
27
25
  File "<stdin>", line 1, in <module>
28
26
 
29
- File "<stdin>", line 2, in get_hottel_information
27
+ File "<stdin>", line 5, in get_hottel_information
30
28
 
31
- File "C:\Users\a.sakata\Anaconda3\lib\urllib\request.py", line 222, in urlopen
32
-
33
- return opener.open(url, data, timeout)
34
-
35
- File "C:\Users\a.sakata\Anaconda3\lib\urllib\request.py", line 531, in open
36
-
37
- response = meth(req, response)
38
-
39
- File "C:\Users\a.sakata\Anaconda3\lib\urllib\request.py", line 641, in http_response
40
-
41
- 'http', request, response, code, msg, hdrs)
29
+ TypeError: 'type' object is not subscriptable```
42
-
43
- File "C:\Users\a.sakata\Anaconda3\lib\urllib\request.py", line 569, in error
44
-
45
- return self._call_chain(*args)
46
-
47
- File "C:\Users\a.sakata\Anaconda3\lib\urllib\request.py", line 503, in _call_chain
48
-
49
- result = func(*args)
50
-
51
- File "C:\Users\a.sakata\Anaconda3\lib\urllib\request.py", line 649, in http_error_default
52
-
53
- raise HTTPError(req.full_url, code, msg, hdrs, fp)
54
-
55
- urllib.error.HTTPError: HTTP Error 400: Bad Request
56
-
57
- ```