์ต๊ทผ python3 conda ํ๊ฒฝ์์ pip install zipfile๋ก ํ์ฌ ๋ง์คํฐ๋ฅผ ์ค์นํ์ต๋๋ค.
base_url = ' http://...........127.0.0.1 :8082'
request.get(base_url)
์ถฉ๋
UniodeError๋ก ๋๋ฉ๋๋ค.
python3.6/encodings/idna.py",
165ํ, ์ธ์ฝ๋ฉ
raise UnicodeError("๋ ์ด๋ธ์ด ๋น์ด ์๊ฑฐ๋ ๋๋ฌด ๊น๋๋ค.")
UnicodeError: ๋ ์ด๋ธ์ด ๋น์ด ์๊ฑฐ๋ ๋๋ฌด ๊น๋๋ค.
๋น์ ์ ์ด๊ฒ์ ์ก์ ์ ์์ต๋๊น?
ํ์์ ์ํด ์ ์ฒด ์ญ์ถ์ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
>>> requests.get(base_url)
Traceback (most recent call last):
File "/Users/cory/.pyenv/versions/3.6.0/lib/python3.6/encodings/idna.py", line 165, in encode
raise UnicodeError("label empty or too long")
UnicodeError: label empty or too long
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/cory/Documents/Python/requests_org/requests/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/Users/cory/Documents/Python/requests_org/requests/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/cory/Documents/Python/requests_org/requests/requests/sessions.py", line 493, in request
prep.url, proxies, stream, verify, cert
File "/Users/cory/Documents/Python/requests_org/requests/requests/sessions.py", line 666, in merge_environment_settings
env_proxies = get_environ_proxies(url, no_proxy=no_proxy)
File "/Users/cory/Documents/Python/requests_org/requests/requests/utils.py", line 692, in get_environ_proxies
if should_bypass_proxies(url, no_proxy=no_proxy):
File "/Users/cory/Documents/Python/requests_org/requests/requests/utils.py", line 676, in should_bypass_proxies
bypass = proxy_bypass(netloc)
File "/Users/cory/.pyenv/versions/3.6.0/lib/python3.6/urllib/request.py", line 2616, in proxy_bypass
return proxy_bypass_macosx_sysconf(host)
File "/Users/cory/.pyenv/versions/3.6.0/lib/python3.6/urllib/request.py", line 2593, in proxy_bypass_macosx_sysconf
return _proxy_bypass_macosx_sysconf(host, proxy_settings)
File "/Users/cory/.pyenv/versions/3.6.0/lib/python3.6/urllib/request.py", line 2566, in _proxy_bypass_macosx_sysconf
hostIP = socket.gethostbyname(hostonly)
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long)
์ด์ ๋ํด ์ฐ๋ฆฌ๊ฐ ํ ์ ์๋ ์ผ์ ๋ง์ง ์์ต๋๋ค. ์ค๋ฅ๋ ํ์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ๋์ต๋๋ค(ํนํ, urllib proxy_bypass
ํจ์์์). socket.gethostbyname
๋ฅผ ํธ์ถํ ํ์์ฑ์ ๋๋ผ๋ Python 3์๋ง ์กด์ฌํฉ๋๋ค. ์ด ๊ธฐ๋ฅ์ ๋จ์ํ ํ์ํ์ง ์์ ์ํฉ์์๋ ์ ๋์ฝ๋ ํธ์คํธ ์ด๋ฆ์ ์๋์ผ๋ก IDNA ์ธ์ฝ๋ฉํ๊ณ ํด๋น IDNA ์ธ์ฝ๋๊ฐ ์ด๋ฅผ ์ฌ๋ฐ๋ฅด๊ฒ ๊ฑฐ๋ถํฉ๋๋ค.
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์๋ ์ ์ผํ ๋ฐฉ๋ฒ์ URL์ ์ด๋ค ํํ๋ก๋ ์ ๊ทํํ๋ ํจ์ฌ ๋ ์ค๋งํธํ URL ์ฒ๋ฆฌ ๊ตฌํ์ผ๋ก ์ด๋ํ๋ ๊ฒ์ ๋๋ค. ๊ฐ์ฅ ์ข์ ํ๋ณด๋ ํ์ดํผ๋งํฌ์ด์ง๋ง ํ์ดํผ๋งํฌ ๋ ๋น์ทํ ์ด์ ๋ก ์ด์ ๋ํด ์ฐจ๋จํฉ๋๋ค(IDNA ์ธ์ฝ๋ฉ์ ์๋ํ๊ณ ์คํจํจ).
์ด๊ฒ์ URL ํธ์คํธ ๋ ธ๋ฉ๋ผ์ด์ ๋ฅผ ์ฌ์ฉํ์ฌ ํ์ดํผ๋งํฌ๋ฅผ ํ์ฅํ ๋ค์ ์ฒ๋ฆฌํจ์ผ๋ก์จ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ ์์ ์ ์๋ฏธํฉ๋๋ค. ๊ทธ๋ฌ๋ WHATWG URL ์ฌ์๋ ์ด๋ฌํ ํ์์ URL์ ๊ธ์งํ๋ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค. ๊ทธ๋ ๋ค๋ฉด Chrome์ด ์ ์ํํ๋ฏ๋ก ์ด์ ๋ฅผ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค(Safari๋ ๊ทธ๋ ์ง ์์).
์ด๋ฅผ ์ํํ๋ ๋ฐ ํ์ํ ์์ ์ ์์ ๊ฐ์ํ ๋ ์ด๋ฅผ ์ฉ์ธํ ์ด์ ๊ฐ ์์ต๋๋ค. URL์ ํฉ๋ฆฌ์ ์ผ๋ก ์๋ํ ๊ฒ์ผ๋ก ์์๋๋ ๊ฒ๊ณผ๋ ๋งค์ฐ ๊ฑฐ๋ฆฌ๊ฐ ๋ฉ๊ธฐ ๋๋ฌธ์ ํด๊ฒฐ๋์ง ์์ ๊ฒ์ด๋ฏ๋ก ์ด URL์ ๋ซ๊ณ ์ถ์ต๋๋ค.
ํ์์ URL์ ๋ํด ๋ค์๊ณผ ๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค.
https://key:[email protected]/path/file.json
๊ธธ์ด๋ 132์์ ๋๋ค.
@johnpaulhayes ๊ทธ๊ฒ์ ์ฌ์ ํ โโ์์ฒญ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ฌธ์ ๊ฐ ์๋์ง๋ง, ๋ํ ์คํ ์ค์ด๋ฏ๋ก ์ ๋ฐ์ดํธ๋ฅผ ์ญ์ ํ ๊ฒ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.
๊ทธ๊ฒ์ ๊ทธ๊ฒ์ ํ๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๋ url์ ์ ์ฒด ๊ธธ์ด๊ฐ ์๋๋ผ ๋จ์ง ๊ทธ๊ฒ์ ํ ๋ถ๋ถ์ ๋๋ค. ํธ์คํธ ์ด๋ฆ์ ์ฒซ ๋ฒ์งธ ๋ถ๋ถ์ด 64์๋ณด๋ค ๊ธธ๋ฉด idna ์ธ์ฝ๋๊ฐ URL์์ ์ค๋จ๋๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ด์ ๊ฐ ๋ฌด์์ด๋ ๊ฑฐ๊ธฐ์๋ ํค์ ๋น๋ฐ๋ ํฌํจ๋์ด ์์ต๋๋ค. ๋ฐ๋ผ์ ๊ธฐ๋ณธ ๊ธฐ๋ฅ์ด ์์ ๋ ๋๊น์ง python3์ ํผํ๊ฑฐ๋ ๊ธด " key:secret@example " ๋ฌธ์์ด์ ํผํ์ญ์์ค(๊ธด API ํค๋ฅผ ํผํจ์ผ๋ก์จ). ์ด์ python tracker์ ๋ฒ๊ทธ๋ฅผ ์ ์ถํ์ต๋๋ค.
ํ์ด์ฌ ์ธก ๋ฌธ์ ์ ๊ด์ฌ์ด ์๋ ์ฌ๋๋ค์ ์ํด
https://bugs.python.org/issue32958
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
ํ์ด์ฌ ์ธก ๋ฌธ์ ์ ๊ด์ฌ์ด ์๋ ์ฌ๋๋ค์ ์ํด
https://bugs.python.org/issue32958