티스토리 뷰
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 |
- Total
- Today
- Yesterday
- SPARK
- java
- airflow
- 백준
- 오류
- Linux
- error
- 하이브
- S3
- bash
- mysql
- SQL
- 하둡
- 알고리즘
- AWS
- yarn
- Hadoop
- ubuntu
- oozie
- emr
- Python
- Tez
- 정올
- HIVE
- 파이썬
- nodejs
- build
- 다이나믹
- hbase
- HDFS
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |