파이썬3 urllib.urlopen 서버 에러
조회수 2759회
안녕하세요! 파이썬 3.6.1/헤로쿠/우분투에서 서버를 구동 중입니다. urllib을 이용해서 데이터를 불러오는 특별할 거 없는 코드가 로컬에서는 잘 돌아가는데 헤로쿠에 디플로이하면 계속 에러가 뜹니다.
def get_lyrics(artist, song_title):
artist = artist.lower()
song_title = song_title.lower()
url = "http://azlyrics.com/lyrics/" + artist + "/" + song_title + ".html"
try:
content = urlopen(url).read()
soup = BeautifulSoup(content, 'html.parser')
lyrics = str(soup)
up_partition = '<!-- Usage of azlyrics.com content by any third-party lyrics provider is prohibited by our licensing agreement. Sorry about that. -->'
down_partition = '<!-- MxM banner -->'
lyrics = lyrics.split(up_partition)[1]
lyrics = lyrics.split(down_partition)[0]
lyrics = lyrics.replace('<br/>', '').replace('</div>', '').strip()
return lyrics
except HTTPError as e:
print(e.code)
print(e.reason)
print(e.headers)
print(sys.exc_info())
return "Sorry, no results."
정말 하나도 특별할 거 없는 코드이고요. 심지어 이거 말고 단순 검색만 하는 거는 같은 원리의 코드인데 아무 문제 없이 잘 돌아갑니다. 이게 가사를 불러오는 코드인데 데이터가 넘쳐서 그런 걸까요...? 헤로쿠는 http가 1MB까지는 아무 문제 없이 잘 돌아가고 그 이상부터는 사용자의 인터넷 환경에 좌우된다고 다큐멘트에 있던데... 근데 가사가 용량이 크면 얼마나 크다고... 아무래도 다른 문제인 것 같습니다.
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
뭐가 문제인지 전혀 감이 잡히지 않습니다. 도와주세요 ㅠㅠ
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력