質問編集履歴

5

誤植の修正

2018/06/02 06:34

投稿

khaii21
khaii21

スコア65

test CHANGED
File without changes
test CHANGED
@@ -258,6 +258,6 @@
258
258
 
259
259
 
260
260
 
261
- equestsモジュールを使ったCookie認証のやり方をご存知の方がいらっしゃいましたら
261
+ requestsモジュールを使ったCookie認証のやり方をご存知の方がいらっしゃいましたら
262
262
 
263
263
  ご教授頂けないでしょうか。

4

エラー修正

2018/06/02 06:34

投稿

khaii21
khaii21

スコア65

test CHANGED
File without changes
test CHANGED
@@ -199,3 +199,65 @@
199
199
  >>> 200
200
200
 
201
201
  ```
202
+
203
+
204
+
205
+ ### 少し見えてきたこと
206
+
207
+ 該当のURLですが、requestsモジュールを使うとレスポンスが返って来ました。
208
+
209
+ ```
210
+
211
+ import requests
212
+
213
+
214
+
215
+ post = {
216
+
217
+ "action": "login",
218
+
219
+ "account": "アカウント"
220
+
221
+ "password": "パスワード"
222
+
223
+ }
224
+
225
+
226
+
227
+ hoge_url = "https://hoge.co.jp/login"
228
+
229
+ response = response.post(URL, data=post)
230
+
231
+ print(response.text)
232
+
233
+
234
+
235
+ ```
236
+
237
+
238
+
239
+ Python初心者であるため、色々と検索して下記の手法を組んだのですが、
240
+
241
+ こちらはCookie認証が必要との情報を見かけて取り入れました。
242
+
243
+ ```
244
+
245
+ opener = build_opener(HTTPCookieProcessor((CookieJar()))
246
+
247
+ data = urlencode(post).encode(encoding)
248
+
249
+ response = opener.open(hoge_url, data)
250
+
251
+ ```
252
+
253
+ 上記とrequestsモジュールとの違いをきちんと理解できていませんが、
254
+
255
+ もし上記と同様なことをrequestsモジュールを使って出来るのであれば、きちんと
256
+
257
+ 認証が通るのではないかと考えています。
258
+
259
+
260
+
261
+ equestsモジュールを使ったCookie認証のやり方をご存知の方がいらっしゃいましたら
262
+
263
+ ご教授頂けないでしょうか。

3

エラーメッセージの修正

2018/06/02 06:28

投稿

khaii21
khaii21

スコア65

test CHANGED
File without changes
test CHANGED
@@ -86,7 +86,7 @@
86
86
 
87
87
  File "requests.py", line 1361, in https_open
88
88
 
89
- conteext=self._context, check_hostname=self._check_hostname)
89
+ context=self._context, check_hostname=self._check_hostname)
90
90
 
91
91
  File "requests.py", line 1320, in do_open
92
92
 

2

エラーメッセージを追記

2018/06/02 00:44

投稿

khaii21
khaii21

スコア65

test CHANGED
File without changes
test CHANGED
@@ -46,6 +46,8 @@
46
46
 
47
47
 
48
48
 
49
+ Traceback (most recent call last):
50
+
49
51
  File "hoge.py", line 159, in <module>
50
52
 
51
53
  response = opener.open(hoge_url, data)
@@ -96,7 +98,7 @@
96
98
 
97
99
  ```
98
100
 
99
- backtraceを仕込んで出力したエラー内容を降順(抜粋)
101
+ import backtrace を仕込んで出力したエラー内容を降順(抜粋)
100
102
 
101
103
 
102
104
 

1

エラーメッセージを追記

2018/06/02 00:38

投稿

khaii21
khaii21

スコア65

test CHANGED
File without changes
test CHANGED
@@ -41,6 +41,64 @@
41
41
  実行後、暫くしてから下記のメッセージが出力されてエラー終了します。
42
42
 
43
43
  ```
44
+
45
+ 通常のエラーメッセージ(抜粋)
46
+
47
+
48
+
49
+ File "hoge.py", line 159, in <module>
50
+
51
+ response = opener.open(hoge_url, data)
52
+
53
+ File "requests.py", line 532, in open
54
+
55
+ response = meth(req, response)
56
+
57
+ File "requests.py", line 642, in http_response
58
+
59
+ 'http', request, response, code, msg, hdrs)
60
+
61
+ File "requests.py", line 564, in error
62
+
63
+ result = self._call_chain(*args)
64
+
65
+ File "requests.py", line 504, in _call_chain
66
+
67
+ result = func(*args)
68
+
69
+ File "requests.py", line 756, in http_error_302
70
+
71
+ return self.parent.open(new, timeout=req.timeout)
72
+
73
+ File "requests.py", line 526, in open
74
+
75
+ response = self._open(req, data)
76
+
77
+ File "requests.py", line 544, in _open
78
+
79
+ '_open, req)
80
+
81
+ File "requests.py", line 504, in _call_chain
82
+
83
+ result = func(*args)
84
+
85
+ File "requests.py", line 1361, in https_open
86
+
87
+ conteext=self._context, check_hostname=self._check_hostname)
88
+
89
+ File "requests.py", line 1320, in do_open
90
+
91
+ raise URLError(err)
92
+
93
+ urllib.error.URLError: <urlopen error [Errno 110] Connectopn time out>
94
+
95
+ ```
96
+
97
+ ```
98
+
99
+ backtraceを仕込んで出力したエラー内容を降順(抜粋)
100
+
101
+
44
102
 
45
103
  756 request.py http_error_302 --> return self.parent.open(new, timeout=req.timeout)
46
104