• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

3_5_4.py asyncio 에서 response.status_code 실행 문제

22.12.21 13:50 작성 22.12.21 13:51 수정 조회수 186

0

안녕하세요 강사님,

앞서 synchronous, threading, multiprocessing 에서는

print(f'[Read Contents : {len(response.content)}, Status Code : {response.status_code} from {url}]') 잘 실행이 되어, status code: 200 값을 확인 할 수 있었습니다.

그런데 asyncio에서는 response.status_code가 출력이 안됩니다.

강사님 설명처럼, 그냥 response 값 전체를 출력하면 확인할 수 있지만.. asyncio에서는 왜 response.status_code 가 실행이 안되는지 설명 좀 부탁 드리겠습니다.

답변 1

답변을 작성해보세요.

0

아래 예제를 참고하세요.

후에 aiohttp를 사용하셔서 출력하시면 됩니다.

의도한대로 출력이 되지 않을 떄는 항상 공식 레퍼런스에서 메소드를 제공하는지 찾아보시길 바래요.

https://stackoverflow.com/questions/46445019/aiohttp-when-is-the-response-status-available

 

resp object is available inside async with block. Therefore resp.status is available too. Also you can call await on some methods, like resp.text() but is doesn't release control of async with block. You can work with resp even after await has been called.

 

ohwhy님의 프로필

ohwhy

질문자

2022.12.21

아네~ 감사합니다.