Last active
July 26, 2018 11:58
-
-
Save neoneo40/47bf3b460b345ea79630 to your computer and use it in GitHub Desktop.
I don't know encoding in python3. Reference: http://www.slideshare.net/daesung7kang/character-encoding-in-python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from urllib.parse import quote, unquote | |
str1 = '인코딩 제발ㅠㅠ' | |
str1.encode('euc-kr') | |
# b'\xc0\xce\xc4\xda\xb5\xf9 \xc1\xa6\xb9\xdf\xa4\xd0\xa4\xd0' | |
str_euckr = quote(str1.encode('euc-kr')) | |
str_euckr | |
# '%C0%CE%C4%DA%B5%F9%20%C1%A6%B9%DF%A4%D0%A4%D0' | |
# 여기에서 6번째 줄처럼 나와야 되는데.. 이렇게 나옴. | |
unquote(str_euckr) | |
# '���ڵ� ���ߤФ�' | |
unquote(str_euckr).decode('euc-kr') | |
# --------------------------------------------------------------------------- | |
# AttributeError Traceback (most recent call last) | |
# <ipython-input-35-0f3add5492cc> in <module>() | |
# ----> 1 unquote(str_euckr).decode('euc-kr') | |
# AttributeError: 'str' object has no attribute 'decode' | |
# 성공! | |
unquote(str_euckr, encoding='euc-kr') | |
# '인코딩 제발ㅠㅠ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
삽질

- 그래서 나온 것이 urlencode테스트

- [requests/test_requests.py at 6d0017ee6a242433b2a05e78ae57ae0b84ad4b13 · kennethreitz/requests · GitHub](https://github.com/kennethreitz/requests/blob/6d0017ee6a242433b2a05e78ae57ae0b84ad4b13/test_requests.py): 잘 정리되어 있으니 참고하자.