Development/python
pip install 시 after connection broken by NewConnectionError
mkdir
2021. 12. 6. 01:00
현상
- 개발 서버에서
pip install ~
로 패키지 설치시 설치가 안됨 - 무슨 일인고, 하고 봤더니 커넥션이 안된다고 한다.
$ pip install pandas
pip install pandas
Collecting pandas
Cache entry deserialization failed, entry ignored
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f194f196290>: Failed to establish a new connection: [Errno -2] \xec\x9d\xb4\xeb\xa6\x84 \xed\x98\xb9\xec\x9d\x80 \xec\x84\x9c\xeb\xb9\x84\xec\x8a\xa4\xeb\xa5\xbc \xec\x95\x8c \xec\x88\x98 \xec\x97\x86\xec\x8a\xb5\xeb\x8b\x88\xeb\x8b\xa4',)': /simple/pandas/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f194f1963d0>: Failed to establish a new connection: [Errno -2] \xec\x9d\xb4\xeb\xa6\x84 \xed\x98\xb9\xec\x9d\x80 \xec\x84\x9c\xeb\xb9\x84\xec\x8a\xa4\xeb\xa5\xbc \xec\x95\x8c \xec\x88\x98 \xec\x97\x86\xec\x8a\xb5\xeb\x8b\x88\xeb\x8b\xa4',)': /simple/pandas/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f194f196510>: Failed to establish a new connection: [Errno -2] \xec\x9d\xb4\xeb\xa6\x84 \xed\x98\xb9\xec\x9d\x80 \xec\x84\x9c\xeb\xb9\x84\xec\x8a\xa4\xeb\xa5\xbc \xec\x95\x8c \xec\x88\x98 \xec\x97\x86\xec\x8a\xb5\xeb\x8b\x88\xeb\x8b\xa4',)': /simple/pandas/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f194f196650>: Failed to establish a new connection: [Errno -2] \xec\x9d\xb4\xeb\xa6\x84 \xed\x98\xb9\xec\x9d\x80 \xec\x84\x9c\xeb\xb9\x84\xec\x8a\xa4\xeb\xa5\xbc \xec\x95\x8c \xec\x88\x98 \xec\x97\x86\xec\x8a\xb5\xeb\x8b\x88\xeb\x8b\xa4',)': /simple/pandas/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f194f196790>: Failed to establish a new connection: [Errno -2] \xec\x9d\xb4\xeb\xa6\x84 \xed\x98\xb9\xec\x9d\x80 \xec\x84\x9c\xeb\xb9\x84\xec\x8a\xa4\xeb\xa5\xbc \xec\x95\x8c \xec\x88\x98 \xec\x97\x86\xec\x8a\xb5\xeb\x8b\x88\xeb\x8b\xa4',)': /simple/pandas/
파악
- 가장먼저 인터넷과의 연결 여부 파악
$ ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=116 time=35.9 ms
$ ifcnofig eth0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet xxx.xxx.xxx.xxx netmask 255.255.255.0 broadcast xxx.xxx.xxx.255 inet6 xxxx::xxx:xxxx:xxxx:xxxx prefixlen 64 scopeid 0x20<link> ether ~:~:~:~:~:~ txqueuelen 1000 (Ethernet) ... eno1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 ether ~:~:~:`:~:~ txqueuelen 1000 (Ethernet) docker0: ... ...
- 인터넷 연결은 정상. 그렇다면 DNS는 제대로 잡혀있는지?
$ ping google.com PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. ping: google.com: Temporary failure in name resolution
- DNS이상이다. Ubuntu20.04 OS를 사용하므로, 네트워크 설정은 netplan에서 해준다.
$ cat /etc/netplan/01\*
# Let NetworkManager manage all devices on this system
network:
ethernets:
eno1:
addresses: \[192.168.0.15/24\]
gateway4: 192.168.0.1
dhcp4: false
nameservers:
addresses: \[8.8.8.8, 8.8.4.4\]
version: 2
renderer: NetworkManager
$ sudo netplan apply
- 문제 발견. 잘못된 인터페이스(eno1)를 정상 인터페이스(eth0)로 변경해준다. 이후 적용
- 그리고 다시 google.com으로 핑을 날려본다.
$ ping google.com 64 bytes from nrt12s47-in-f14.1e100.net (xxx.xxx.xxx.xxx): icmp_seq=3 ttl=116 time=34.0 ms
- 성공. 그럼이제 제대로 pip로 패키지를 받아보자.
$ pip install pandas Collecting pandas Downloading pandas-1.3.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.5 MB) |████████████████████████████████| 11.5 MB 8.4 MB/s Collecting pytz>=2017.3 Downloading pytz-2021.3-py2.py3-none-any.whl (503 kB) |████████████████████████████████| 503 kB 70.1 MB/s Collecting numpy>=1.17.3; platform_machine != "aarch64" and platform_machine != "arm64" and python_version < "3.10" Downloading numpy-1.21.4-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.7 MB) |████████████████████████████████| 15.7 MB 53.8 MB/s Collecting python-dateutil>=2.7.3 Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB) |████████████████████████████████| 247 kB 68.3 MB/s Collecting six>=1.5 Downloading six-1.16.0-py2.py3-none-any.whl (11 kB) Installing collected packages: pytz, numpy, six, python-dateutil, pandas Successfully installed numpy-1.21.4 pandas-1.3.4 python-dateutil-2.8.2 pytz-2021.3 six-1.16.0
- 패키지 다운로드 성공.
분석
- 컴파일 없이
update-alternative
모듈로 파이썬을 설치할 경우 가장 흔하게 발생하는No module name: apt-pkg
처럼 베이스가 되는 OS쪽에 문제가 생긴것이었다. 이젠 별별 에러를 들고 찾아오는 사람들이 많아져서 어디서 문제가 생겼는지 대충 감이 온다. 이게 짬에서 나오는 바이브라는 건가... - 그래서 대체 누가 DNS를 이상한거로 바꿔놨는지는 3일인 지난 지금도 불명이다. 애초에 쓰는 사람도 두명 뿐인데, 그 중 한명은 장기 출장으로 외부로 나가있었고, 다른 한 사람은 그걸 만진 적이 없다고 하니...
- 더해서 pip 패키지가 urllib3.connection 관련해 에러를 띄우는 것을 보니, pip 는 내부적으로 urllib3으로 요청을 보내 패키지 목록을 파악하고 다운로드를 실행하는 것으로 보인다.
- 그리고 에러메세지 최후방의 /simple/pandas라는 주소가 왠지 자꾸 걸려서 www.pypi.org 뒤에 저 주소를 붙여 접속을 시도해봤더니... 마치 alpine linux의 index같은 패키지 사이트가 등장했다. 기타 matplotlib, scipy등 다른 모듈들도 테스트해봤지만 동일한 위치를 가르키고 있었다. 저 simple이 index 파일의 역할을 하고 있는 듯 하다.
- 그리고 /simple/pandas 내부에는 각종 판다스 버전의 아카이브가 하이퍼링크로 존재하고 있었다. 각종 OS 버전이 붙은거로 봐서,
uname
등으로 다운로드를 시도하는 서버의 아키텍처를 파악하고 거기에 맞는 위치의 filename 및 version으로 리디렉션 해주는게 아닐까?f'pandas-{version}-{uname}'
이런 식으로...