2026.04.07(Tue)

오유찬·2026년 4월 10일

DE

목록 보기
3/16
xls = pd.read_excel(url, sheet_name=None)

sheet_name=None으로 인수를 전달하면 모든 시트가 dictionary 형태로 반환됨.
sheet_name을 인수로 전달하지 않으면 첫 번째 시트만 반환된다.
각 스프레드 시트의 이름을 알고 싶다면 xls.keys()로 키값을 구해야 된다.

웹 개발에서 tag soup는 웹페이지의 html 코드가 구조나 문법 면에서 얽힌 상태를 뜻한다.
BeautifulSoup는 이 tag soup를 보기 좋게 만들고 필요한 정보를 추출하는 것이다.

# error
authentication = {'name':'john@doe.com', 'password':'Warp_ExtrapolationsForfeited2'}


response = requests.get('http://localhost:3000/albums', auth=authentication)

if(response.status_code == 200):
	print("Success!")
elif(response.status_code == 401):
	print('Authentication failed')
else:
	print('Another error occurred')

auth 인자는 기본 인증을 위해 사용자 이름과 비밀번호가 들어있는 Tuple을 기대한다.
따라서 dictionary 형태로 값을 전달하면 'dict' object is not callable이라는 에러가 뜬다.

reqeusts.get() 에서 URL 매개변수로 값을 전달하는 인자는 params 다.
headers에서 API 키에 대한 값을 전달할 때는

headers = {"Authorization" : 'Bearer 8apDFHaNJMxy8Kt818aa6b4a0ed0514b5d3'}

Bearer는 소유자라는 의미다. → 토큰의 소유자로서 토큰 전달

content-type header : API가 응답을 어떤 형식으로 보냈는지를 나타낼 때 사용

  • 내가 보내는 것

accept header : Request 헤더에서만 주로 사용한다

  • 받고 싶은 데이터의 형식

GET 요청에서 URL 쿼리 파라미터 → params 인자

json 데이터를 보낼 때(POST 요청) → json 인자

raise_for_status() : enable raising exceptions for returned error statuscodes

except HTTPError as http_err : catch error responses from the API server
except ConnectionError as conn_err : catch any connections errors

profile
열심히 하면 재밌다

0개의 댓글