반응형
import json
from urllib.request import urlopen
def get_my_country_code():
try:
request = "https://geolocation-db.com/json/%"
with urlopen(request) as url:
data = json.loads(url.read().decode())
c_code = data['country_code']
if c_code == None:
return 'KR'
return c_code
except:
return 'KR'
country_code = get_my_country_code()
print(country_code)
반응형
'Programing > python' 카테고리의 다른 글
파이썬 개발환경 설정을 위해 필요한 항목들에 대해서 (0) | 2023.02.26 |
---|---|
파이썬 커리큘럼 (0) | 2023.02.26 |
python 외부 ip 주소 가지고 오기 (0) | 2021.05.11 |
외부 쓰레드에서 qt ui 접근 (0) | 2021.05.11 |
OpenGL in python : create window (0) | 2021.03.15 |