質問するログイン新規登録

質問編集履歴

5

誤植の修正

2018/06/02 06:34

投稿

khaii21
khaii21

スコア70

title CHANGED
File without changes
body CHANGED
@@ -128,5 +128,5 @@
128
128
  もし上記と同様なことをrequestsモジュールを使って出来るのであれば、きちんと
129
129
  認証が通るのではないかと考えています。
130
130
 
131
- equestsモジュールを使ったCookie認証のやり方をご存知の方がいらっしゃいましたら
131
+ requestsモジュールを使ったCookie認証のやり方をご存知の方がいらっしゃいましたら
132
132
  ご教授頂けないでしょうか。

4

エラー修正

2018/06/02 06:34

投稿

khaii21
khaii21

スコア70

title CHANGED
File without changes
body CHANGED
@@ -98,4 +98,35 @@
98
98
  >>> import requests
99
99
  >>> res = requests.get('https://hoge.co.jp/login')
100
100
  >>> 200
101
- ```
101
+ ```
102
+
103
+ ### 少し見えてきたこと
104
+ 該当のURLですが、requestsモジュールを使うとレスポンスが返って来ました。
105
+ ```
106
+ import requests
107
+
108
+ post = {
109
+ "action": "login",
110
+ "account": "アカウント"
111
+ "password": "パスワード"
112
+ }
113
+
114
+ hoge_url = "https://hoge.co.jp/login"
115
+ response = response.post(URL, data=post)
116
+ print(response.text)
117
+
118
+ ```
119
+
120
+ Python初心者であるため、色々と検索して下記の手法を組んだのですが、
121
+ こちらはCookie認証が必要との情報を見かけて取り入れました。
122
+ ```
123
+ opener = build_opener(HTTPCookieProcessor((CookieJar()))
124
+ data = urlencode(post).encode(encoding)
125
+ response = opener.open(hoge_url, data)
126
+ ```
127
+ 上記とrequestsモジュールとの違いをきちんと理解できていませんが、
128
+ もし上記と同様なことをrequestsモジュールを使って出来るのであれば、きちんと
129
+ 認証が通るのではないかと考えています。
130
+
131
+ equestsモジュールを使ったCookie認証のやり方をご存知の方がいらっしゃいましたら
132
+ ご教授頂けないでしょうか。

3

エラーメッセージの修正

2018/06/02 06:28

投稿

khaii21
khaii21

スコア70

title CHANGED
File without changes
body CHANGED
@@ -42,7 +42,7 @@
42
42
  File "requests.py", line 504, in _call_chain
43
43
  result = func(*args)
44
44
  File "requests.py", line 1361, in https_open
45
- conteext=self._context, check_hostname=self._check_hostname)
45
+ context=self._context, check_hostname=self._check_hostname)
46
46
  File "requests.py", line 1320, in do_open
47
47
  raise URLError(err)
48
48
  urllib.error.URLError: <urlopen error [Errno 110] Connectopn time out>

2

エラーメッセージを追記

2018/06/02 00:44

投稿

khaii21
khaii21

スコア70

title CHANGED
File without changes
body CHANGED
@@ -22,6 +22,7 @@
22
22
  ```
23
23
  通常のエラーメッセージ(抜粋)
24
24
 
25
+ Traceback (most recent call last):
25
26
  File "hoge.py", line 159, in <module>
26
27
  response = opener.open(hoge_url, data)
27
28
  File "requests.py", line 532, in open
@@ -47,7 +48,7 @@
47
48
  urllib.error.URLError: <urlopen error [Errno 110] Connectopn time out>
48
49
  ```
49
50
  ```
50
- backtraceを仕込んで出力したエラー内容を降順(抜粋)
51
+ import backtrace を仕込んで出力したエラー内容を降順(抜粋)
51
52
 
52
53
  756 request.py http_error_302 --> return self.parent.open(new, timeout=req.timeout)
53
54
  504 request.py _call_chain --> = func(*args)

1

エラーメッセージを追記

2018/06/02 00:38

投稿

khaii21
khaii21

スコア70

title CHANGED
File without changes
body CHANGED
@@ -20,6 +20,35 @@
20
20
  ### 発生している問題・エラーメッセージ
21
21
  実行後、暫くしてから下記のメッセージが出力されてエラー終了します。
22
22
  ```
23
+ 通常のエラーメッセージ(抜粋)
24
+
25
+ File "hoge.py", line 159, in <module>
26
+ response = opener.open(hoge_url, data)
27
+ File "requests.py", line 532, in open
28
+ response = meth(req, response)
29
+ File "requests.py", line 642, in http_response
30
+ 'http', request, response, code, msg, hdrs)
31
+ File "requests.py", line 564, in error
32
+ result = self._call_chain(*args)
33
+ File "requests.py", line 504, in _call_chain
34
+ result = func(*args)
35
+ File "requests.py", line 756, in http_error_302
36
+ return self.parent.open(new, timeout=req.timeout)
37
+ File "requests.py", line 526, in open
38
+ response = self._open(req, data)
39
+ File "requests.py", line 544, in _open
40
+ '_open, req)
41
+ File "requests.py", line 504, in _call_chain
42
+ result = func(*args)
43
+ File "requests.py", line 1361, in https_open
44
+ conteext=self._context, check_hostname=self._check_hostname)
45
+ File "requests.py", line 1320, in do_open
46
+ raise URLError(err)
47
+ urllib.error.URLError: <urlopen error [Errno 110] Connectopn time out>
48
+ ```
49
+ ```
50
+ backtraceを仕込んで出力したエラー内容を降順(抜粋)
51
+
23
52
  756 request.py http_error_302 --> return self.parent.open(new, timeout=req.timeout)
24
53
  504 request.py _call_chain --> = func(*args)
25
54
  564 request.py error --> result = self._call_chain(*args)