thinh-vu / vnstock

A powerful Python library for getting rich data from the Vietnam Stock Market using just a few lines of code
https://vnstocks.com
Other
562 stars 139 forks source link

retry when connection time out #30

Closed tonyvu1289 closed 1 year ago

tonyvu1289 commented 1 year ago

Sometimes the request will be timeout. This is the way i fix it.

from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
session = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)

and then replace request.get() by session.get()

thinh-vu commented 1 year ago

Hi @tonyvu1289, Thank you for sharing. Could you please provide further details on where and how we should utilize this code block?