
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
1주차 숙제에서 <정답>과 같이 new_rows를 정의하지 않고, sheet.rows를 그대로 입력하면 아스키코드 에러가 뜨는데, 그렇다면 <정답>과 같이 새이름을 정의해서 제목에 해당하는 행을 반드시 제거해주어야 되는 조건인가요?
<정답>
new_rows=list(sheet.rows)[1:]
for row in new_rows:
<질문자의 코드>
for row in sheet.rows:
전체 화면 캡처
작성한 코드 및 에러 메세지
import urllib.request
import openpyxl
wb = openpyxl.load_workbook('관리종목.xlsx')
sheet = wb['종목']
for row in sheet.rows:
url = f'https://ssl.pstatic.net/imgfinance/chart/item/area/year3/{row[1].value}.png'
urllib.request.urlretrieve(url, f"images/{row[0].value}.png")
<에러 메세지>
UnicodeEncodeError Traceback (most recent call last)
<ipython-input-15-f839437e1fcc> in <cell line: 6>()
6 for row in sheet.rows:
7 url = f'https://ssl.pstatic.net/imgfinance/chart/item/area/year3/{row[1].value}.png'
----> 8 urllib.request.urlretrieve(url, f"images/{row[0].value}.png")
10 frames
/usr/lib/python3.9/http/client.py in _encode_request(self, request)
1212 def _encode_request(self, request):
1213 # ASCII also helps prevent CVE-2019-9740.
-> 1214 return request.encode('ascii')
1215
1216 def _validate_method(self, method):
UnicodeEncodeError: 'ascii' codec can't encode characters in position 38-41: ordinal not in range(128)
