Qiita(20)今日は何をやってもうまくいかない。明日のために３項目エラー等記録。

Qiitaの使い方、プログラムからの利用
https://qiita.com/kaizen_nagoya/items/86dfcd81dd99d9e57021

にあげた事項を順にやろうとして挫折。
3台のMacを利用。

原因は

1 brewの導入がユーザ依存
 機材によってbrewの管理IDが違う
2 python2と3の管理が不十分
 python2中心の機材とpython3中心の機材あり
3 pipが未導入の機材があった 
 python2のpipが未導入
4 DHCP, DNSの設定がサーバと端末で不整合
　午前１時間、午後１時間、wiresharkで測定。
　ARPの応答がなく、DNSがひけてない。
  別機材（ルータ）経由で接続
　一部は無線代替。

1: 
[メモ] Qiita: 投稿記事の閲覧数をコマンドラインで取得
https://qiita.com/mt08/items/57411d9618725d58a41f

# 環境
mac with brew
bash :  os付属
curl :  brew install curl
jq :  brew install jq
pup : brew install pup

```
$ brew install curl
==> Downloading https://homebrew.bintray.com/bottles/curl-7.61.0.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring curl-7.61.0.high_sierra.bottle.tar.gz
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/curl/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/curl/lib
    CPPFLAGS: -I/usr/local/opt/curl/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/curl/lib/pkgconfig

==> Summary
🍺  /usr/local/Cellar/curl/7.61.0: 433 files, 3.1MB

$ brew install jq
==> Installing dependencies for jq: oniguruma
==> Installing jq dependency: oniguruma
==> Downloading https://homebrew.bintray.com/bottles/oniguruma-6.8.2.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring oniguruma-6.8.2.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/oniguruma/6.8.2: 17 files, 1.2MB
==> Installing jq
==> Downloading https://homebrew.bintray.com/bottles/jq-1.5_3.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring jq-1.5_3.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/jq/1.5_3: 19 files, 946.6KB

$ brew install pup
==> Downloading https://homebrew.bintray.com/bottles/pup-0.4.0.high_sierra.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring pup-0.4.0.high_sierra.bottle.1.tar.gz
🍺  /usr/local/Cellar/pup/0.4.0: 5 files, 3.9MB

```

# 手順 

ブラウザでログインして、ログイン用クッキーを取得(user_session_keyと_qiita_login_session)。


Chrome：環境設定 ： 詳細設定(一番下) ： セキュリティ ： コンテンツの設定 ： Cookie : すべてのCookieとさーとデータ：一覧から「qiita.com」選択
![qiita1.png](https://qiita-image-store.s3.amazonaws.com/0/51423/5e929ada-d29a-a77d-6435-843e86057ada.png)


```q.sh
QIITA_COOKIE_user_session_key="0...g"
QIITA_COOKIE__qiita_login_session="d...d"
curl -s -H "Cookie: user_session_key=${QIITA_COOKIE_user_session_key}; _qiita_login_session=${QIITA_COOKIE__qiita_login_session}" http://qiita.com | pup '.userInfo_urlName a json{}' | jq '.[] .text' -r
```


```
$ chmod +x q.sh
$ ./q.sh
EOF
```


2:
[PR]Qiitaでストックした投稿を検索するアプリをReact + Railsで作った
https://qiita.com/takayuki-ochiai/items/c99692b758b4dce98d52

ざっくりGulp.js入門（Mac向け）
https://qiita.com/kazukichi/items/884a1379eea5918689ed

```
$ brew install node
touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/.git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/px4/homebrew-px4/.git/FETCH_HEAD: Permission denied
fatal: Unable to create '/usr/local/Homebrew/.git/index.lock': Permission denied
error: could not lock config file .git/config: Permission denied
==> Downloading https://homebrew.bintray.com/bottles/node-10.2.1.sierra.bottle.tar.g
######################################################################## 100.0%
==> Pouring node-10.2.1.sierra.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/node/10.2.1: 5,301 files, 51.9MB
KM-S05:~ administrator$ sudo npm install gulp -g
Password:
npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated graceful-fs@3.0.11: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated graceful-fs@1.2.3: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
WARN notice [SECURITY] minimatch has the following vulnerability: 1 high. Go here for more details: https://nodesecurity.io/advisories?search=minimatch&version=0.2.14 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
WARN notice [SECURITY] minimatch has the following vulnerability: 1 high. Go here for more details: https://nodesecurity.io/advisories?search=minimatch&version=2.0.10 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
WARN notice [SECURITY] lodash has the following vulnerability: 1 low. Go here for more details: https://nodesecurity.io/advisories?search=lodash&version=1.0.2 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.
/usr/local/bin/gulp -> /usr/local/lib/node_modules/gulp/bin/gulp.js
+ gulp@3.9.1
added 253 packages in 9.698s
KM-S05:~ administrator$ pwd
/Users/administrator
KM-S05:~ administrator$ mkdir qiita
KM-S05:~ administrator$ cd qiita
KM-S05:qiita administrator$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (qiita) 
version: (1.0.0) 
description: 
entry point: (index.js) 
test command: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to /Users/administrator/qiita/package.json:

{
  "name": "qiita",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this ok? (yes) yes

┌──────────────────────────────────────────────────────────────────┐
│                     npm update check failed                      │
│               Try running with sudo or get access                │
│               to the local update config store via               │
│ sudo chown -R $USER:$(id -gn $USER) /Users/administrator/.config │
└──────────────────────────────────────────────────────────────────┘
KM-S05:qiita administrator$ sudo npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (qiita) 
version: (1.0.0) 
description: new
git repository: 
keywords: qiita
author: O.K.
license: (ISC) 
About to write to /Users/administrator/qiita/package.json:

{
  "name": "qiita",
  "version": "1.0.0",
  "description": "new",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "O.K.",
  "license": "ISC",
  "keywords": [
    "qiita"
  ]
}


Is this ok? (yes) yes
KM-S05:qiita administrator$ npm install --save-dev gulp
npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated graceful-fs@3.0.11: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated graceful-fs@1.2.3: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN qiita@1.0.0 No repository field.

+ gulp@3.9.1
added 253 packages in 4.389s

┌──────────────────────────────────────────────────────────────────┐
│                     npm update check failed                      │
│               Try running with sudo or get access                │
│               to the local update config store via               │
│ sudo chown -R $USER:$(id -gn $USER) /Users/administrator/.config │
└──────────────────────────────────────────────────────────────────┘
KM-S05:qiita administrator$ sudo npm install --save-dev gulp
npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated graceful-fs@3.0.11: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated minimatch@2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated graceful-fs@1.2.3: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN qiita@1.0.0 No repository field.

+ gulp@3.9.1
updated 1 package in 3.553s
KM-S05:qiita administrator$ ls
node_modules		package-lock.json	package.json
```

3:
Qiita API v2 を使って自身の全投稿をエクスポートする Python スクリプトを書いた
https://qiita.com/sta/items/5074df5fcb81d890897b#

```
$ brew install pip
Error: No available formula with the name "pip" 
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can install
pip via the instructions at:
  https://pip.readthedocs.io/en/stable/installing/
$ brew install curl
==> Downloading https://homebrew.bintray.com/bottles/curl-7.61.0.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring curl--7.61.0.sierra.bottle.tar.gz
==> Caveats
curl is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have curl first in your PATH run:
  echo 'export PATH="/usr/local/opt/curl/bin:$PATH"' >> ~/.bash_profile

For compilers to find curl you may need to set:
  export LDFLAGS="-L/usr/local/opt/curl/lib"
  export CPPFLAGS="-I/usr/local/opt/curl/include"

For pkg-config to find curl you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/curl/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/curl/7.61.0: 433 files, 3.1MB
```

```
pip install requests
-bash: pip: command not found
$ curl -O https://bootstrap.pypa.io/2.7/get-pip.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   162  100   162    0     0    261      0 --:--:-- --:--:-- --:--:--   261
KM-S10:~ brew_manager$ python get-pip.py --user   
  File "get-pip.py", line 1
    <html>
    ^
SyntaxError: invalid syntax
KM-S10:~ brew_manager$ python get-pip.py 
  File "get-pip.py", line 1
    <html>
    ^
SyntaxError: invalid syntax
KM-S10:~ brew_manager$ cat get-pip.py 
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
$ cd 
$ cd Downloads/
$ python get-pip.py 
The directory '/Users/brew_manager/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/brew_manager/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
  Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 23.7MB/s 
Collecting wheel
  Downloading https://files.pythonhosted.org/packages/81/30/e935244ca6165187ae8be876b6316ae201b71485538ffac1d718843025a9/wheel-0.31.1-py2.py3-none-any.whl (41kB)
    100% |████████████████████████████████| 51kB 15.3MB/s 
Installing collected packages: pip, wheel
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip'
Consider using the `--user` option or check the permissions.

KM-S10:Downloads brew_manager$ python get-pip.py --user
The directory '/Users/brew_manager/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/brew_manager/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
  Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 19.4MB/s 
Collecting wheel
  Downloading https://files.pythonhosted.org/packages/81/30/e935244ca6165187ae8be876b6316ae201b71485538ffac1d718843025a9/wheel-0.31.1-py2.py3-none-any.whl (41kB)
    100% |████████████████████████████████| 51kB 15.7MB/s 
Installing collected packages: pip, wheel
  The script wheel is installed in '/Users/brew_manager/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-18.0 wheel-0.31.1
:Downloads brew_manager$ pip install requests
-bash: pip: command not found
$ pip -V
-bash: pip: command not found
$ cd /Users/brew_manager/Library/Python/2.7/bin
$ ls
pip	pip2	pip2.7	wheel
$ pip install requestws
-bash: pip: command not found
$ ls -al
total 32
¥drwxr-xr-x  6 brew_manager  staff  204  8 27 15:26 .
drwx------  4 brew_manager  staff  136  8 27 15:26 ..
-rwxr-xr-x  1 brew_manager  staff  215  8 27 15:26 pip
-rwxr-xr-x  1 brew_manager  staff  215  8 27 15:26 pip2
-rwxr-xr-x  1 brew_manager  staff  215  8 27 15:26 pip2.7
-rwxr-xr-x  1 brew_manager  staff  212  8 27 15:26 wheel
KM-S10:bin brew_manager$ ./pip install requests
The directory '/Users/brew_manager/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/brew_manager/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting requests
  Downloading https://files.pythonhosted.org/packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl (91kB)
    100% |████████████████████████████████| 92kB 3.8MB/s 
Collecting idna<2.8,>=2.5 (from requests)
  Downloading https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 24.0MB/s 
Collecting certifi>=2017.4.17 (from requests)
  Downloading https://files.pythonhosted.org/packages/df/f7/04fee6ac349e915b82171f8e23cee63644d83663b34c539f7a09aed18f9e/certifi-2018.8.24-py2.py3-none-any.whl (147kB)
    100% |████████████████████████████████| 153kB 8.3MB/s 
Collecting urllib3<1.24,>=1.21.1 (from requests)
  Downloading https://files.pythonhosted.org/packages/bd/c9/6fdd990019071a4a32a5e7cb78a1d92c53851ef4f56f62a3486e6a7d8ffb/urllib3-1.23-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 27.7MB/s 
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 28.4MB/s 
Installing collected packages: idna, certifi, urllib3, chardet, requests
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/idna'
Consider using the `--user` option or check the permissions.

:bin brew_manager$ ./pip install requests --user
The directory '/Users/brew_manager/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/brew_manager/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting requests
  Downloading https://files.pythonhosted.org/packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl (91kB)
    100% |████████████████████████████████| 92kB 3.7MB/s 
Collecting idna<2.8,>=2.5 (from requests)
  Downloading https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 23.8MB/s 
Collecting certifi>=2017.4.17 (from requests)
  Downloading https://files.pythonhosted.org/packages/df/f7/04fee6ac349e915b82171f8e23cee63644d83663b34c539f7a09aed18f9e/certifi-2018.8.24-py2.py3-none-any.whl (147kB)
    100% |████████████████████████████████| 153kB 9.2MB/s 
Collecting urllib3<1.24,>=1.21.1 (from requests)
  Downloading https://files.pythonhosted.org/packages/bd/c9/6fdd990019071a4a32a5e7cb78a1d92c53851ef4f56f62a3486e6a7d8ffb/urllib3-1.23-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 31.5MB/s 
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 31.4MB/s 
Installing collected packages: idna, certifi, urllib3, chardet, requests
  The script chardetect is installed in '/Users/brew_manager/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed certifi-2018.8.24 chardet-3.0.4 idna-2.7 requests-2.19.1 urllib3-1.23
:bin brew_manager$ pwd
/Users/brew_manager/Library/Python/2.7/bin
:bin brew_manager$ 
```


```
$mkdir qiita
$cd qiita
$vi qiita.py
$vi qiita.sh
$chmod +x qiita.sh
$./qiita.sh

Traceback (most recent call last):
  File "qiita.py", line 95, in <module>
    r = get(url, params, headers)
  File "qiita.py", line 29, in get
    r = requests.get(url, params=params, proxies=proxies, headers=headers)
  File "/Users/brew_manager/Library/Python/2.7/lib/python/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/Users/brew_manager/Library/Python/2.7/lib/python/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/brew_manager/Library/Python/2.7/lib/python/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/brew_manager/Library/Python/2.7/lib/python/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/Users/brew_manager/Library/Python/2.7/lib/python/site-packages/requests/adapters.py", line 495, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', error(54, 'Connection reset by peer'))
```

```qiita.sh
QIITA_ACCESS_TOKEN="4...6"

python qiita.py
```

ps. 
# 参考文献(reference)

ソフトウェア開発に役立つ　心理学的現象、行動経済学の概念など　15題
https://qiita.com/arai-wa/items/4c7629276ced7e933235

Qiita(0)Qiita関連記事一覧（自分）
https://qiita.com/kaizen_nagoya/items/58db5fbf036b28e9dfa6

プログラマが知っていると良い「公序良俗」
https://qiita.com/kaizen_nagoya/items/9fe7c0dfac2fbd77a945

一覧の一覧( The directory of directories of mine.) Qiita(100)
https://qiita.com/kaizen_nagoya/items/7eb0e006543886138f39

＜この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。＞
This article is an individual impression based on the individual's experience. It has nothing to do with the organization or business to which I currently belong.

# 文書履歴(document history)
ver. 0.10 初稿　2018/08/27
ver. 0.11 参考文献、文書履歴追記 2018/09/22
### 最後までおよみいただきありがとうございました。
いいね　💚、フォローをお願いします。
####  Thank you very much for reading to the last sentence.
Please press the like icon 💚　and follow me for your happy life.