Swingby

파이썬 에러] urllib2 라이브러리 모듈 에러 본문

카테고리 없음

파이썬 에러] urllib2 라이브러리 모듈 에러

Opine 2020. 2. 24. 13:40

파이썬3로 업데이트 되면서 모듈 urllib2를 불러올때 에러가 생긴다.

 

삭제된게 아니고 파이썬3 urllib 모듈안에 기존것들이 다 들어가 있으니 urllib로 변경해서 사용하면 된다..

 

또한 많이 사용하는 urlopen은 urllib.request안에 있다.

 

Python 2 
Python 3 (변경 후)
import urllib2 

print urllib2.urlopen("http://www.example.com").read() 

import urllib.request 

print(urllib.request.urlopen("http://www.example.com").read()) 


또는



from urllib.request import urlopen 

print(urlopen("http://www.example.com").read())

 

기존 코드에 익숙해있는 사람이라면 import urllib.request로 바꿔서 쓰면 해결!

Comments