커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
new_rows=list(sheet.rows)[1:] 이렇게 새 이름을 정의해서 제목 행을 반드시 제거해주어야 되는 조건인가요?
undefined주차
북마크
임*주
댓글
5
추천
0
조회수
20
조회수
20
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


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)




취소
 공유
취소
댓글 0
댓글 알림
나의얼굴