[python] request 함수를 사용하여 오류가 발생했을 때 재작업하는 방법

2022. 11. 16. 09:34·python

request 를 이용하여 http 요청을 처리할 때 재작업을 해야 하는 경우가 있습니다.

 

하나는 서버에 연결후 정상적으로 응답이 와서 응답을 보고 재작업을 해야 하는 경우 retry 모듈을 이용하여 재작업을 처리할 수 있습니다. 다른 방법은 서버에 정상적으로 연결이 되지 않는 경우 다시 재작업을 해야 하는 경우 데코레이터 모듈을 이용하여 재작업을 할 수 있습니다.

 

retry 모듈

retry 모듈은 서버의 응답에 따라서 재작업을 진행할 수 있습니다. 서버가 특정 응답을 보낼때는 재작업을 한다는 룰을 가질 수 있는 경우 사용할 수 있습니다.

 

https://brownbears.tistory.com/613

 

[Python] requests 모듈 retry 추가하기

requests 모듈은 https://brownbears.tistory.com/198 와 같이 간단하게 사용할 순 있지만 retry 옵션은 존재하지 않습니다. 아래는 반복문, try-except문으로 retry 기능을 추가하는 것이 아닌 requests 모듈에서 제

brownbears.tistory.com

 

https://www.peterbe.com/plog/best-practice-with-retries-with-requests

 

Best practice with retries with requests - Peterbe.com

I have a lot of code that does response = requests.get(...) in various Python projects. This is nice and simple but the problem is that networks are unreliable. So it's a good idea to wrap these network calls with retries. Here's one such implementation.

www.peterbe.com

decorator를 사용하는 방법

데코레이터는 서버에 연결이 안되는 경우 사용할 수 있습니다. 네트워크 상황이 좋지 않거나, 서버 앞에 프록시 서버가 있어서 연결이 제대로 되지 않는 경우 사용할 수 있습니다.

 

pip로 retry 모듈을 설치하여 사용할 수도 있고, 직접 구현해서 사용할 수도 있습니다.

 

 

https://stackoverflow.com/questions/50246304/using-python-decorators-to-retry-request

 

Using Python decorators to retry request

I have multiple functions in my script which does a REST API api requests.As i need to handle the error scenarios i have put a retry mechanism as below. no_of_retries = 3 def check_status(): f...

stackoverflow.com

 

https://medium.com/analytics-vidhya/retry-decorator-in-python-55d0729755c7

 

Retry decorator in Python

In this post , we will be discussing about Retry decorator and how to use it in python.

medium.com

 

https://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/

 

Trying out a Retry decorator in Python - SaltyCrane Blog

Trying out a Retry decorator in Python The Python wiki has a Retry decorator example which retries calling a failure-prone function using an exponential backoff algorithm. I modified it slightly to check for exceptions instead of a False return value to in

www.saltycrane.com

 

반응형
저작자표시 비영리 동일조건 (새창열림)

'python' 카테고리의 다른 글

[python] 함수 변수의 *, ** 전달자 확인  (0) 2023.07.02
[python] pandas import 시 UserWarning: Could not import the lzma module. Your installed Python is incomplete 오류  (0) 2023.03.21
[python] requests 라이브러리에서 exceptions.MaxRetryError 가 발생하는 경우 처리 방법  (0) 2022.05.17
[python] http를 이용한 post 구현  (0) 2022.05.17
[python] datetime 변환시 타임존을 설정해야 하는 이유  (0) 2022.05.17
'python' 카테고리의 다른 글
  • [python] 함수 변수의 *, ** 전달자 확인
  • [python] pandas import 시 UserWarning: Could not import the lzma module. Your installed Python is incomplete 오류
  • [python] requests 라이브러리에서 exceptions.MaxRetryError 가 발생하는 경우 처리 방법
  • [python] http를 이용한 post 구현
hs_seo
hs_seo
Hello World!
    반응형
  • hs_seo
    개발자로 살아남기
    hs_seo
  • 전체
    오늘
    어제
    • 전체 (1140)
      • 개발자 (21)
        • 개발에 유의할 점 (0)
        • 면접 (5)
      • IT 소식 (5)
        • 업계 (1)
      • java (51)
        • 디자인패턴 (3)
        • apache-common (1)
      • 개념 (47)
        • 자료구조 (4)
        • 함수형사고 (8)
        • 디자인패턴 (1)
      • 데이터분석 (1)
      • python (67)
        • 코드조각 (12)
        • 라이브러리 (2)
      • 빅데이터 (418)
        • zookeeper (5)
        • hadoop (78)
        • hdfs (12)
        • hive (127)
        • hbase (16)
        • spark (40)
        • scala (4)
        • trino (3)
        • oozie (41)
        • Hue (9)
        • R (5)
        • sqoop (6)
        • flume (3)
        • elasticsearch (2)
        • airflow (16)
        • kafka (3)
        • kubernetes (10)
        • openstack (3)
        • flink (2)
        • redis (2)
      • 빅데이터 강좌 (2)
      • 알고리즘 (131)
        • 알고리즘 (1)
        • 백준 (61)
        • 정올 (41)
        • 더블릿 (5)
        • 프로그래머스 (1)
      • 프로그래밍 언어 (30)
        • go (4)
        • js (9)
        • .Net (6)
        • Jsp (1)
        • ansible (3)
        • terraform (6)
      • Tools (56)
        • docker (2)
        • macbook (6)
        • maven (3)
        • sublime (1)
      • 프레임워크 (25)
        • [JS] angularjs (2)
        • [JS] node.js (19)
        • [Java] spring (2)
        • Android (2)
      • 데이타베이스 (43)
        • SQLD (5)
        • Oracle (1)
        • MySQL (8)
        • ADsP (2)
      • 리눅스 (25)
        • Bash (61)
      • GCP (5)
      • AWS (34)
        • EC2 (2)
        • EMR (14)
      • 정보보안기사 (4)
        • 네트워크 (1)
      • 개인 (80)
        • 업무실수 (0)
        • 책 (9)
        • 교육 (3)
        • 여행 (17)
        • 영화 (12)
        • 음악 (2)
        • 피규어 (4)
        • 게임 (3)
        • 생각 (7)
        • 기타 (10)
        • 좋은글 (5)
        • 좋은 사이트 (2)
  • 블로그 메뉴

    • 홈
    • 태그
    • 미디어로그
    • 위치로그
    • 방명록
  • 링크

    • 빅데이터-하둡,하이브로 시작하기
    • 빅데이터-스칼라, 스파크로 시작하기
    • Kaggle에서 파이썬으로 데이터 분석 시작하기
    • 쉘스크립트 개발 시작하기
    • 개발자가 데이터 분석 준전문가 되기
    • 데브쿠마
  • 공지사항

  • 인기 글

  • 태그

    다이나믹
    정올
    Tez
    build
    Python
    oozie
    알고리즘
    mysql
    HDFS
    java
    error
    파이썬
    airflow
    하이브
    AWS
    ubuntu
    백준
    하둡
    emr
    Hadoop
    S3
    HIVE
    Linux
    hbase
    k8s
    nodejs
    bash
    yarn
    오류
    SPARK
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
hs_seo
[python] request 함수를 사용하여 오류가 발생했을 때 재작업하는 방법
상단으로

티스토리툴바