본문 바로가기
파이썬

파이썬 AttributeError: 'module' object has no attribute 'urlretrieve'

by º기록 2021. 1. 11.
반응형

웹 사이트에서 mp3를 다운로드 한 다음 함께 결합하는 프로그램을 작성하려고하지만 파일을 다운로드하려고 할 때마다이 오류가 발생합니다.

Traceback (most recent call last):
File "/home/tesla/PycharmProjects/OldSpice/Voicemail.py", line 214, in <module> main()
File "/home/tesla/PycharmProjects/OldSpice/Voicemail.py", line 209, in main getMp3s()
File "/home/tesla/PycharmProjects/OldSpice/Voicemail.py", line 134, in getMp3s
raw_mp3.add = urllib.urlretrieve("http://www-scf.usc.edu/~chiso/oldspice/m-b1-hello.mp3")
AttributeError: 'module' object has no attribute 'urlretrieve'

이 문제를 일으키는 라인은

raw_mp3.add = urllib.urlretrieve("http://www-scf.usc.edu/~chiso/oldspice/m-b1-hello.mp3")

 

해결 방법

 

Python 3을 사용하고 있으므로 더 이상 urllib 모듈이 없습니다. 여러 모듈로 분할되었습니다.

이것은 urlretrieve와 동일합니다.

import urllib.request
data = urllib.request.urlretrieve("http://...")

urlretrieve는 Python 2.x에서와 똑같은 방식으로 작동하므로 잘 작동합니다.

원래:

 

참조 페이지 https://stackoverflow.com/questions/17960942

 

 

반응형

댓글